Drops MQTT/mosquitto connection on wifi router reboot.
Posted: 26 Sep 2015, 14:28
Hello all
Posting this as an easy solution to a problem that maybe others have too. It would be really useful if something similar was implemented.
My WiFi router (which my EasyESP sensors connect to) seems to reboot itself one or two times every 24 hours (haven't really looked into why and if it can be changed). The EasyESP automatically restores the WiFi connection to the router when it's back online. But the MQTT/mosquitto connection does not restore. I solved this by adding a few lines of code in the watchdog starting on line 374 in ESPEasy.ino (meaning it will run every 30 sec):
In some situations it said mosquitto was disconnected, tried to reconnect and seemed to succeed, but on the next run it was still disconnected. Therefore i added the disconnect() wich seems to solve that problem. Also, don't know if the delay is really needed. But it seems to work!
Posting this as an easy solution to a problem that maybe others have too. It would be really useful if something similar was implemented.
My WiFi router (which my EasyESP sensors connect to) seems to reboot itself one or two times every 24 hours (haven't really looked into why and if it can be changed). The EasyESP automatically restores the WiFi connection to the router when it's back online. But the MQTT/mosquitto connection does not restore. I solved this by adding a few lines of code in the watchdog starting on line 374 in ESPEasy.ino (meaning it will run every 30 sec):
Code: Select all
if (MQTTclient.connected()) {
Serial.println("Mosquitto connetion ok.");
} else {
Serial.println("Mosquitto disconneted. Trying to reconnect.");
MQTTclient.disconnect();
delay(1000);
MQTTConnect();
}