Closed eht584 closed 3 years ago
I have looked something regarding the MQTT reconnect problems, is currently so that as soon as the connection to the broker goes away the ESP is no longer accessible because he hangs in the reconnect loop. I have tried something around and found that the solution is actually already in the folder:
https://github.com/knolleary/pubsubclient/blob/master/examples/mqtt_reconnect_nonblocking/mqtt_reconnect_nonblocking.ino.
Here is continuously trying to reestablish the connection without blocking the loop.
@eht584 I have no idea, as I have never had any of my ESPs hang using MQTT. I run about 20 devices using MQTT technology. What broker are you using? I use mosquitto on a router running openwrt linux on it.
@eht584 if you are willing, try changing the following lines Swap line 207 with if(mqtt_client.connected()){Serial.println("MQTT connected");} Swap line 216 with a return; Swap line 543 with if(mqtt_client.connected()){mqtt_client.loop();}
See if that solves your problem. Basically this will skip the connect mqtt loop and try it again on next main loop
Hey @SwiCago, really great job, I tested with my heater and it works good, but I have problem only, if connecting to MQTT broker fault (bad Internet). the reconnection function block the main loop and I can't use the Button (Sonoff) turn OFF.
Best Eduard