lbussy / AsyncWiFiManager

ESP8266 Async WiFi Connection Manager with Captive Web Portal
https://github.com/lbussy/AsyncWiFiManager
MIT License
7 stars 4 forks source link

Fix after merging merge_tzapu_4319a66 (2f76338 ) #6

Closed lbussy closed 4 years ago

lbussy commented 4 years ago

Good changes merged from upspream, two re-breaks:

lbussy commented 4 years ago

Fix for the 4-way connect faulure:

diff --git a/src/AsyncWiFiManager.cpp b/src/AsyncWiFiManager.cpp
index de96d1c..aa80c33 100644
--- a/src/AsyncWiFiManager.cpp
+++ b/src/AsyncWiFiManager.cpp
@@ -3434,6 +3434,12 @@ void AsyncWiFiManager::WiFiEvent(WiFiEvent_t event, system_event_info_t info)
         {
             _lastconxresulttmp = 7; // hack in wrong password internally, sdk emit WIFI_REASON_AUTH_EXPIRE on some routers on auth_fail
         }
+        else if (info.disconnected.reason == WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT)
+        {
+            // Hack to reset due to ESP not connecting after flashing
+            DEBUG_WM(DEBUG_VERBOSE, "[EVENT] WIFI_REASON: WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT detected, resetting.");
+            ESP.restart();
+        }
         else
             _lastconxresulttmp = WiFi.status();
         if (info.disconnected.reason == WIFI_REASON_NO_AP_FOUND)

Debug printing fix:

diff --git a/src/AsyncWiFiManager.cpp b/src/AsyncWiFiManager.cpp
index aa80c33..86cde79 100644
--- a/src/AsyncWiFiManager.cpp
+++ b/src/AsyncWiFiManager.cpp
@@ -1075,12 +1075,17 @@ uint8_t AsyncWiFiManager::waitForConnectResult(uint16_t timeout)
         status = WiFi.status();
         // @todo detect additional states, connect happens, then dhcp then get ip, there is some delay here, make sure not to timeout if waiting on IP
         if (status == WL_CONNECTED || status == WL_CONNECT_FAILED)
+            if (_debug)
+                Serial.println();
         {
             return status;
         }
-        DEBUG_WM(DEBUG_VERBOSE, F("."));
+        if (_debug)
+            Serial.print(".");
         delay(100);
     }
+    if (_debug)
+        Serial.println();
     return status;
 }

@@ -1315,9 +1320,12 @@ bool AsyncWiFiManager::WiFi_scanNetworks(bool force, bool async)
             DEBUG_WM(DEBUG_ERROR, "[ERROR] scan waiting");
             while (WiFi.scanComplete() == WIFI_SCAN_RUNNING)
             {
-                DEBUG_WM(DEBUG_ERROR, ".");
+                if (_debug)
+                    Serial.print(".");
                 delay(100);
             }
+            if (_debug)
+                Serial.println();
             _numNetworks = WiFi.scanComplete();
         }
         else if (res >= 0)
@@ -3429,6 +3437,7 @@ void AsyncWiFiManager::WiFiEvent(WiFiEvent_t event, system_event_info_t info)
     // DEBUG_WM(DEBUG_VERBOSE,"[EVENT]",event);
     if (event == SYSTEM_EVENT_STA_DISCONNECTED)
     {
+        if(_debug) Serial.println();
         DEBUG_WM(DEBUG_VERBOSE, "[EVENT] WIFI_REASON:", info.disconnected.reason);
         if (info.disconnected.reason == WIFI_REASON_AUTH_EXPIRE || info.disconnected.reason == WIFI_REASON_AUTH_FAIL)
         {
@@ -3443,7 +3452,9 @@ void AsyncWiFiManager::WiFiEvent(WiFiEvent_t event, system_event_info_t info)
         else
             _lastconxresulttmp = WiFi.status();
         if (info.disconnected.reason == WIFI_REASON_NO_AP_FOUND)
-            DEBUG_WM(DEBUG_VERBOSE, "[EVENT] WIFI_REASON: NO_AP_FOUND");
+        {
+            DEBUG_WM(DEBUG_VERBOSE, F("[EVENT] WIFI_REASON: NO_AP_FOUND"));
+        }
 #ifdef esp32autoreconnect
         DEBUG_WM(DEBUG_VERBOSE, "[Event] SYSTEM_EVENT_STA_DISCONNECTED, reconnecting");
         WiFi.reconnect();