SwiCago / HarviaWiFi

Wifi Control of Harvia KIP Sauna Heater
GNU Lesser General Public License v3.0
41 stars 10 forks source link

Blocking reconnect MQTT function. #8

Closed eht584 closed 3 years ago

eht584 commented 3 years ago

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

eht584 commented 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.

SwiCago commented 3 years ago

@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.

SwiCago commented 3 years ago

@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