Fix for wifi reconnection issues, delay retry for 30 sec #919

This commit is contained in:
fvanroie 2025-07-29 22:35:14 +02:00
parent f08eafc07f
commit acebfb980a

View File

@ -509,7 +509,7 @@ void wifiSetup()
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN); WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
wifiReconnect(); wifiReconnect();
WiFi.setAutoReconnect(true); // done in wifiEvery5Seconds WiFi.setAutoReconnect(false); // done in wifiEvery5Seconds
LOG_TRACE(TAG_WIFI, F(D_WIFI_CONNECTING_TO), wifiSsid); LOG_TRACE(TAG_WIFI, F(D_WIFI_CONNECTING_TO), wifiSsid);
} }
#endif #endif
@ -517,28 +517,31 @@ void wifiSetup()
bool wifiEvery5Seconds() bool wifiEvery5Seconds()
{ {
static uint8_t disconnectionPeriod = 0; // WiFi disconnection period counter
#if defined(STM32F4xx) #if defined(STM32F4xx)
if(wifiShowAP()) { // no ssid is set yet wait for user on-screen input if(wifiShowAP()) { // no ssid is set yet wait for user on-screen input
return false; return false;
} }
#else #else
if(WiFi.getMode() == WIFI_AP || WiFi.getMode() == WIFI_AP_STA) { if(WiFi.getMode() == WIFI_AP || WiFi.getMode() == WIFI_AP_STA) {
LOG_DEBUG(TAG_WIFI, F("5sec mode AP %d"), WiFi.getMode()); LOG_DEBUG(TAG_WIFI, F("5sec mode AP %d"), WiFi.getMode());
return false; return false;
} }
#endif #endif
if(WiFi.status() == WL_CONNECTED && WiFi.localIP() > 0) { if(WiFi.status() == WL_CONNECTED && WiFi.localIP() > 0) {
return true; disconnectionPeriod = 0; // Reset the counter if connection was established
} return true;
}
// Issue #919 : Reconnects happens to quickly if(WiFi.status() != WL_CONNECTED) { // If WiFi disconnected...
// if(wifiEnabled) { if(++disconnectionPeriod >= 6) { // If 30 seconds have passed since the disconnection...
// LOG_WARNING(TAG_WIFI, F("No Connection... retry %d"), network_reconnect_counter); disconnectionPeriod = 0; // Restart timeout period
// wifiReconnect(); wifiReconnect(); // Reconnect to WiFi
// } }
}
return false; return false;
} }
bool wifiValidateSsid(const char* ssid, const char* pass) bool wifiValidateSsid(const char* ssid, const char* pass)