Page 1 of 1

Drops MQTT/mosquitto connection on wifi router reboot.

Posted: 26 Sep 2015, 14:28
by larsbjorke
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):

Code: Select all

 
 if (MQTTclient.connected()) {
  Serial.println("Mosquitto connetion ok.");
} else {
  Serial.println("Mosquitto disconneted. Trying to reconnect.");
  MQTTclient.disconnect();
  delay(1000);
  MQTTConnect();
}
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!

Re: Drops MQTT/mosquitto connection on wifi router reboot.

Posted: 27 Sep 2015, 10:35
by Martinus
Thanks for testing and debugging! We will include it in the next release.

Re: Drops MQTT/mosquitto connection on wifi router reboot.

Posted: 27 Sep 2015, 22:36
by asm7100
How you set at ip to the mac add in your router?

A router renew the connection every 24 hours normal.