Check mqtt connection state ESP32



I’m implementing a reconnection method in my application for Wi-FI and mqtt. So far the reconnection method for Wi-Fi works, but how can I check if the thing is still connected to the mqtt broker, if not, re-establish the connection?

something like:

if thing.mqtt.is_connected() == false:



Hello @Marcel,

the mqtt library automatically handles mqtt reconnection which is detected when the reception channel is somehow interrupted and no incoming activity has been registered lately (no response to ping requests which are sent periodically).

Due to current automatic reconnection method I do not recommend to also handle it manually :slight_smile:


Ok great, thank you. My reconnection procedure now works (without touching mqtt reconnect).