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:
1technophile committed 2019-07-26 10:55:17 +02:00
1 parent e0c8d93802
commit 87c85eabe0
1 file changed
+5
+5
View File
@@ -828,8 +828,10 @@ 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 (WiFi.status() == WL_CONNECTED){
if (reconnect()) { if (reconnect()) {
lastReconnectAttempt = 0; lastReconnectAttempt = 0;
} else { } else {
@@ -848,6 +850,9 @@ void loop()
} }
#endif #endif
} }
}else{
trc("wifi disconnected");
}
} }
} else { //connected } else { //connected
// MQTT loop // MQTT loop