diff --git a/WiFiManager.cpp b/WiFiManager.cpp index eec8f8f..1a4048e 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -573,7 +573,17 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) { connRes = waitForConnectResult(); } - _lastconxresult = connRes; + 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; + } + } + #endif + } return connRes; } @@ -736,7 +746,6 @@ String WiFiManager::getScanItemOut(){ // token precheck, to speed up replacements on large ap lists String HTTP_ITEM_STR = FPSTR(HTTP_ITEM); - // toggle icons with percentage HTTP_ITEM_STR.replace("{qp}", FPSTR(HTTP_ITEM_QP)); HTTP_ITEM_STR.replace("{h}",_scanDispOptions ? "" : "h"); @@ -1344,6 +1353,25 @@ void WiFiManager::reportStatus(String &page){ else { str = FPSTR(HTTP_STATUS_OFF); str.replace(FPSTR(T_v),WiFi_SSID()); + if(_lastconxresult == WL_STATION_WRONG_PASSWORD){ + // wrong password + str.replace(FPSTR(T_c),"D"); // class + str.replace(FPSTR(T_r),FPSTR(HTTP_STATUS_OFFPW)); + } + else if(_lastconxresult == WL_NO_SSID_AVAIL){ + // connect failed, or ap not found + str.replace(FPSTR(T_c),"D"); + str.replace(FPSTR(T_r),FPSTR(HTTP_STATUS_OFFNOAP)); + } + else if(_lastconxresult == WL_CONNECT_FAILED){ + // connect failed + str.replace(FPSTR(T_c),"D"); + str.replace(FPSTR(T_r),FPSTR(HTTP_STATUS_OFFFAIL)); + } + else{ + str.replace(FPSTR(T_c),""); + str.replace(FPSTR(T_r),""); + } } } else { @@ -1791,7 +1819,7 @@ boolean WiFiManager::validApPassword(){ * @return {[type]} [description] */ String WiFiManager::getWLStatusString(uint8_t status){ - if(status >=0 && status <=6) return WIFI_STA_STATUS[status]; + if(status >=0 && status <=7) return WIFI_STA_STATUS[status]; return FPSTR(S_NA); } diff --git a/WiFiManager.h b/WiFiManager.h index 1b26f96..02c85d3 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -215,7 +215,10 @@ class WiFiManager WiFiMode_t _usermode = WIFI_OFF; String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid uint8_t _lastconxresult = WL_IDLE_STATUS; - + + #ifndef WL_STATION_WRONG_PASSWORD + uint8_t WL_STATION_WRONG_PASSWORD = 7; + #endif // option parameters int _minimumQuality = -1; // filter wifiscan ap by this rssi diff --git a/strings_en.h b/strings_en.h index b198ecb..0212a2c 100644 --- a/strings_en.h +++ b/strings_en.h @@ -43,7 +43,10 @@ const char HTTP_END[] PROGMEM = ""; const char HTTP_ERASEBTN[] PROGMEM = "
"; const char HTTP_STATUS_ON[] PROGMEM = "
Connected to {v}
with IP {i}
"; -const char HTTP_STATUS_OFF[] PROGMEM = "
Not Connected to {v}
"; +const char HTTP_STATUS_OFF[] PROGMEM = "
Not Connected to {v}{r}
"; +const char HTTP_STATUS_OFFPW[] PROGMEM = "
Wrong Password"; +const char HTTP_STATUS_OFFNOAP[] PROGMEM = "
AP not found"; +const char HTTP_STATUS_OFFFAIL[] PROGMEM = "
Could not Connect"; const char HTTP_STATUS_NONE[] PROGMEM = "
No AP set
"; const char HTTP_BR[] PROGMEM = "
"; @@ -226,13 +229,14 @@ const char HTTP_HEAD_CT2[] PROGMEM = "text/plain"; const char * const WIFI_STA_STATUS[] PROGMEM { - "WL_IDLE_STATUS", // STATION_IDLE - "WL_NO_SSID_AVAIL", // STATION_NO_AP_FOUND - "WL_SCAN_COMPLETED", - "WL_CONNECTED", // STATION_GOT_IP - "WL_CONNECT_FAILED",// STATION_CONNECT_FAIL, STATION_WRONG_PASSWORD(NI) - "WL_CONNECTION_LOST", - "WL_DISCONNECTED" + "WL_IDLE_STATUS", // 0 STATION_IDLE + "WL_NO_SSID_AVAIL", // 1 STATION_NO_AP_FOUND + "WL_SCAN_COMPLETED", // 2 + "WL_CONNECTED", // 3 STATION_GOT_IP + "WL_CONNECT_FAILED", // 4 STATION_CONNECT_FAIL, STATION_WRONG_PASSWORD(NI) + "WL_CONNECTION_LOST", // 5 + "WL_DISCONNECTED", // 6 + "WL_STATION_WRONG_PASSWORD" // 7 KLUDGE }; #ifdef ESP32