el-client icon indicating copy to clipboard operation
el-client copied to clipboard

MQTT: reconnect after broken connection?

Open flipsa opened this issue 6 years ago • 0 comments

Hey TVE,

Thanks for esp-link and el-client, your work is much appreciated!

I've been using esp-link (v3.2.47-g9c6530d) succesfully for an Arduino (Mega) project I'm working on and just added MQTT support through el-client (v3.0.alpha0) to publish status and sensor data, which then gets picked up by an mqtt broker running in a Openhab (home automation) instance to display nice graphs from the sensor data.

The problem I'm facing is identical or similar to #8: sometimes the MQTT connection between the el-client and the Openhab instance goes down, usually only for seconds or sometimes in the range of a few minutes. In the serial log I can see that the mqttDisconnect callback is being called a few times (usually twice or three times within a short time like a minute or so) but then the callback is not being called again afterwards, or at least I don't see any "MQTT disconnected" messages on the serial monitor.

If the connection to Openhab is re-established before that, then it resumes publishing status data. However, if the issue persists a bit longer (a few minutes), the mqtt connection is never re-established from the Arduino's side of things, BUT, the esp-link MQTT status info (rssi and heap) will reconnect just fine and I can receive the status data in Openhab without any issues.

How can I make sure that the Arduino also notices that the connection is working again and then start publishing the mqtt data again? I tried manually calling the esp.Sync(); function in the MQTT disconnect callback, but that reliably crashes the Arduino.

Any help is appreciated...

Edit: Added version information for esp-link and el-client.

flipsa avatar May 15 '19 14:05 flipsa