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