While constructing a demo I encountered a problem with losant-mqtt-python. When the connection drops (cable disconnect or any other hardware failure), the thread crashes at the first try to reconnect, raising a ConnectionRefusedError
- the application does not recover.
It can be fixed by changing the self._mqtt_client.reconnect()
line in _cb_client_disconnect()
to something like:
try: self._mqtt_client.reconnect() except ConnectionError as e: print("Reconnect failed due to {}".format(e))
If the exception is not raised, the loop automatically keeps trying to reconnect, so the problem will be solved as soon as a connection is available again.