> > Matthew, I have a big question for better understanding of how weewx deals > with drivers ! > > There is an infinite loop in the driver (while true:). > > So my understanding is that weewx launch the driver as a kind of > background thread that output packet with that yield command ? > So it's just never go out of the while true loop as long as weewx run. > > Then in case of weewx stop, weewx will force exit this infinite loop and > launch the "close_port()" procedure ? >
Yes, the drivers should emit LOOP packets indefinitely, but the engine calling them does not. At the end of an archive period, it raises exception engine.BreakLoop, which breaks the loop. After processing the archive record, it starts the loop again with a call to genLoopPackets () . As you say, it's also true that at program termination it also breaks the loop. by the way, if my understanding is correct, does it mean I shall check > regularly if mqtt connexion is still valid and reconnect if needed ? > The connexion is in the __init__ then, if disconnected for any reason, we > cannot recover, am I right ? > > If your lose the mqtt connection, you should raise an exception of type weewx.WeeWxIOError, or a subclass of weewx.WeeWxIOError. The engine will catch this exception and, by default, after 60 seconds do a restart. This will cause your driver to reload, giving it an opportunity to reconnect with the broker. -tk