Hi Tom,

Thanks for advices !

After a deeper look in python mqtt documentation, it seems that 
"loop_start()" thing take care to make sure we are still connected to 
broker.
if not, it will reconnect.
but it may make sense to check before sending anyway.

also during the weekend I noticed that at reboot, as weewx start before my 
ethernet connexion is fully setup, it seems I get a crash (the driver is 
not able to connect).

Is it possible to use this weewx.WeeWxIOError during the __init__ of the 
driver ?

Best regards,






Le samedi 18 mars 2017 16:07:16 UTC+1, Tom Keffer a écrit :
>
> 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
>

Reply via email to