[Solved] Losant-mqtt-python reconnect issue


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.



Thanks for the report!

We have released losant-mqtt v1.0.1 to address the issue you raised. It will now automatically try to continually reconnect without raising socket exceptions in both non-blocking (manually calling loop) and blocking mode.

Let us know if you run into any other issues!