if wifi is lost the ESP was blocked on a "MQTT connection loop"
To avoid that check the status of wifi connection before trying to connect to mqtt Add of traces
This commit is contained in:
1 parent
e0c8d93802
commit
87c85eabe0
1 file changed
+21
-16
+21
-16
@@ -828,25 +828,30 @@ void loop()
|
||||
//MQTT client connexion management
|
||||
if (!client.connected()) { // not connected
|
||||
if (now - lastReconnectAttempt > 5000) {
|
||||
trc("client disconnected");
|
||||
lastReconnectAttempt = now;
|
||||
// Attempt to reconnect
|
||||
if (reconnect()) {
|
||||
lastReconnectAttempt = 0;
|
||||
} else {
|
||||
#if defined(ESPWifiManualSetup)
|
||||
trc(F("restarting ESP"));
|
||||
#ifdef ESP32
|
||||
ESP.restart();
|
||||
if (WiFi.status() == WL_CONNECTED){
|
||||
if (reconnect()) {
|
||||
lastReconnectAttempt = 0;
|
||||
} else {
|
||||
#if defined(ESPWifiManualSetup)
|
||||
trc(F("restarting ESP"));
|
||||
#ifdef ESP32
|
||||
ESP.restart();
|
||||
#endif
|
||||
#ifdef ESP8266
|
||||
ESP.reset();
|
||||
#endif
|
||||
#elif defined(ESP8266) || defined(ESP32)
|
||||
if (!connectedOnce) {
|
||||
trc(F("reseting wifi manager"));
|
||||
setup_wifimanager(true); // if we didn't connected once to mqtt we reset and start in AP mode again to have a chance to change the parameters
|
||||
}
|
||||
#endif
|
||||
#ifdef ESP8266
|
||||
ESP.reset();
|
||||
#endif
|
||||
#elif defined(ESP8266) || defined(ESP32)
|
||||
if (!connectedOnce) {
|
||||
trc(F("reseting wifi manager"));
|
||||
setup_wifimanager(true); // if we didn't connected once to mqtt we reset and start in AP mode again to have a chance to change the parameters
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}else{
|
||||
trc("wifi disconnected");
|
||||
}
|
||||
}
|
||||
} else { //connected
|
||||
|
||||
Reference in new issue
Block a user