From 3d7074166c35d4f75def32e9ed221624db3f2165 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Tue, 20 Feb 2018 08:49:54 -0600 Subject: [PATCH] #528 using a static var for esp32 event for now to get this working and test. Probably not the best, not sure what the best option is here for esp32 onevent static member function callbacks --- WiFiManager.cpp | 40 +++++++++++++++++++++++++--------------- WiFiManager.h | 5 +++-- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index e3f3624..1ffba8c 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -11,6 +11,7 @@ */ #include "WiFiManager.h" +uint8_t WiFiManager::_lastconxresulttmp = WL_IDLE_STATUS; /** * -------------------------------------------------------------------------------- @@ -575,14 +576,21 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) { if(connRes != WL_SCAN_COMPLETED){ _lastconxresult = connRes; - #ifdef ESP8266 // hack in wrong password detection if(_lastconxresult == WL_CONNECT_FAILED){ - if(wifi_station_get_connect_status() == STATION_WRONG_PASSWORD){ - _lastconxresult = WL_STATION_WRONG_PASSWORD; - } + #ifdef ESP8266 + if(wifi_station_get_connect_status() == STATION_WRONG_PASSWORD){ + _lastconxresult = WL_STATION_WRONG_PASSWORD; + } + #elif defined(ESP32) + // DEBUG_WM("lastconxresulttmp:",getWLStatusString(_lastconxresulttmp)); + if(_lastconxresulttmp != WL_IDLE_STATUS){ + _lastconxresult = _lastconxresulttmp; + _lastconxresulttmp = WL_IDLE_STATUS; + } + #endif } - #endif + DEBUG_WM("lastconxresult:",getWLStatusString(_lastconxresult)); } return connRes; @@ -1945,15 +1953,17 @@ String WiFiManager::WiFi_SSID(){ void WiFiManager::WiFiEvent(WiFiEvent_t event,system_event_info_t info){ #ifdef ESP32 // WiFiManager _WiFiManager; - // if(event == SYSTEM_EVENT_STA_START) WiFi.setHostname("wmtest"); - // if(event == SYSTEM_EVENT_AP_START) WiFi.softAPsetHostname("wmtest"); - if(event == SYSTEM_EVENT_STA_DISCONNECTED){ - // Serial.println(info.disconnected.reason); - if(info.disconnected.reason == WIFI_REASON_AUTH_EXPIRE) Serial.println("*WM: EVENT: WIFI_REASON: AUTH_EXPIRE"); - if(info.disconnected.reason == WIFI_REASON_AUTH_FAIL) Serial.println("*WM: EVENT: WIFI_REASON: AUTH_FAIL"); - if(info.disconnected.reason == WIFI_REASON_NO_AP_FOUND) Serial.println("*WM: EVENT: WIFI_REASON: NO_AP_FOUND"); - // Serial.println("Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); - // _WiFiManager.DEBUG_WM("ESP32 Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); // @todo remove debugging from prod, or change static method + // Serial.print("WM: EVENT: ");Serial.println(event); + if(event == SYSTEM_EVENT_STA_DISCONNECTED){ + if(info.disconnected.reason == WIFI_REASON_AUTH_EXPIRE || info.disconnected.reason == WIFI_REASON_AUTH_FAIL){ + Serial.print("WM: EVENT: WIFI_REASON: ");Serial.println(info.disconnected.reason); + _lastconxresulttmp = 7; + return; + } + // if(event == SYSTEM_EVENT_STA_START) WiFi.setHostname("wmtest"); + // if(event == SYSTEM_EVENT_AP_START) WiFi.softAPsetHostname("wmtest"); + // if(info.disconnected.reason == WIFI_REASON_NO_AP_FOUND) Serial.println("*WM: EVENT: WIFI_REASON: NO_AP_FOUND"); + Serial.println("*WM: Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); WiFi.reconnect(); } #endif @@ -1964,7 +1974,7 @@ void WiFiManager::WiFi_autoReconnect(){ WiFi.setAutoReconnect(_wifiAutoReconnect); #elif defined(ESP32) if(_wifiAutoReconnect){ - DEBUG_WM("ESP32 autoreconnect handler enabled"); + DEBUG_WM("ESP32 event handler enabled"); WiFi.onEvent(WiFiEvent); } #endif diff --git a/WiFiManager.h b/WiFiManager.h index 62917fa..fdb7ddd 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -209,12 +209,13 @@ class WiFiManager // options flags unsigned long _configPortalTimeout = 0; // ms close config portal loop if set (depending on _cp/webClientCheck options) - unsigned long _connectTimeout = 0; // ms stop trying to connect to ap if set + unsigned long _connectTimeout = 10000; // ms stop trying to connect to ap if set unsigned long _configPortalStart = 0; // ms config portal start time (updated for timeouts) unsigned long _webPortalAccessed = 0; // ms last web access time WiFiMode_t _usermode = WIFI_OFF; String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid - uint8_t _lastconxresult = WL_IDLE_STATUS; + uint8_t _lastconxresult = WL_IDLE_STATUS; + static uint8_t _lastconxresulttmp; #ifndef WL_STATION_WRONG_PASSWORD uint8_t WL_STATION_WRONG_PASSWORD = 7;