Community
OpenEnergyMonitor

OpenEnergyMonitor Community

Emonhub interfacer - how is emonhub closing an interfacer?

Tags: #<Tag:0x00007f1bd7cf0ae0>

Hi, does anyone know how emonhub works in some detail? I’m not a python expert and had difficulty reading the code. I made an interfacer for it recently, which worked fine in the end, but a question came up when it wasn’t closing and restarting properly at first…

What’s the termination procedure for an emonhub interfacer?

related question… Is there a function called within an interfacer to called to help close that interfacer?

or do I need to know how interfacers are created to understand how to close them properly?

@pb66 Do you know this one?

Dan, I would need to look at the code again, especially as there have been many changes by many contributors since I last developed for this version.

In general you shouldn’t need to worry about that as each interfacers run is called repeatedly by the main thread, this in turn calls the read, send and action functions, this is where you do your code, you should inherit the run function unchanged and then write your own read, send and/or action functions.

When the main loop no longer calls the run the interacer will not “be running” and the main loop will kill the interfacer thread, this is teh part that will have changed significantly as Trystan changed things, then there were problems that were “resolved” by making the threads auto restart when they crashed etc etc, then more recently a change to Python3 so I don’t know how much of the original code or behaviour is as it was.

What sort of interfacer are you trying to build? Does it need to do something special to end?

Hi Paul,
It’s the sds011 dust sensor which is interfacing by a com port so nothing too complex.

The original sds011 library I’d found was setting up another threading thread and causing a lockup in the read function. So when restarting emonhub nothing would happen until the read function had done a round, which was designed to take a few minutes in the original.

In the end found a non-blocking sds011 library and made a method to use it, so all good.

I didn’t realise so much of the code had been changed by Trys since your initial work, sorry for the hassle.