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
|
//MQTT client connexion management
|
||||||
if (!client.connected()) { // not connected
|
if (!client.connected()) { // not connected
|
||||||
if (now - lastReconnectAttempt > 5000) {
|
if (now - lastReconnectAttempt > 5000) {
|
||||||
|
trc("client disconnected");
|
||||||
lastReconnectAttempt = now;
|
lastReconnectAttempt = now;
|
||||||
// Attempt to reconnect
|
// Attempt to reconnect
|
||||||
if (reconnect()) {
|
if (WiFi.status() == WL_CONNECTED){
|
||||||
lastReconnectAttempt = 0;
|
if (reconnect()) {
|
||||||
} else {
|
lastReconnectAttempt = 0;
|
||||||
#if defined(ESPWifiManualSetup)
|
} else {
|
||||||
trc(F("restarting ESP"));
|
#if defined(ESPWifiManualSetup)
|
||||||
#ifdef ESP32
|
trc(F("restarting ESP"));
|
||||||
ESP.restart();
|
#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
|
#endif
|
||||||
#ifdef ESP8266
|
}
|
||||||
ESP.reset();
|
}else{
|
||||||
#endif
|
trc("wifi disconnected");
|
||||||
#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 { //connected
|
} else { //connected
|
||||||
|
|||||||
Reference in new issue
Block a user