peterhinch / micropython-mqtt

A 'resilient' asynchronous MQTT driver. Recovers from WiFi and broker outages.
MIT License
549 stars 116 forks source link

MQTT reconnect not works #140

Closed vencax closed 1 month ago

vencax commented 1 month ago

I am facing trouble when I restart my MQTT server, the proxy not reconnects.

ESPNow ID: 84fce600cf89

Checking WiFi integrity.

Got reliable connection

Connecting to broker.

Connected to broker.

Gateway 84fce600cf89 connected to broker integration.open-energoman.eu.

RAM free 96112 alloc 40080

RAM free 96112 alloc 40080

RAM free 96112 alloc 40080

RAM free 96112 alloc 40080

RAM free 96112 alloc 40080

RAM free 96112 alloc 40080

RAM free 95824 alloc 40368

WiFi or broker is down.

could be something missing in config?:

mqtt_config["server"] = config['MQTT_SERVER']
mqtt_config["password"] = config['MQTT_PASSWORD']
mqtt_config["user"] = config['MQTT_USER']
mqtt_config["ssid"] = config['SSID']
mqtt_config["wifi_pw"] = config['PASSPHRASE']
mqtt_config["ssl"] = True
mqtt_config["debug"] = True
peterhinch commented 1 month ago

Please explain your test procedure. The client has connected to the broker. Does MQTT work correctly at that point?

When the message "WiFi or broker is down." occurs, how long a period has elapsed since your initial connection? Is it possible that the broker integration.open-energoman.eu. is rejecting the connection for some reason? If the outage is caused by a deliberate policy decision by that provider, then reconnection will be impossible.

vaclavklecanda-ext44263 commented 1 month ago

The connection is established, messages are delivered. The MQTT broker works fine. Then I ssh to the server with the broker and I restart the broker. So it drops all the connections and starts again = it causes "WiFi or broker is down." on ESP32C3 board.

vencax commented 1 month ago

Sorry, my mistake, I have an old version. This commit https://github.com/peterhinch/micropython-mqtt/commit/b29f5e37f541235664ef9a3d7ffe003d19ffc4fa is probably fixing it.