tzapu / WiFiManager

ESP8266 WiFi Connection manager with web captive portal
http://tzapu.com/esp8266-wifi-connection-manager-library-arduino-ide/
MIT License
6.53k stars 1.96k forks source link

Entering wrong password to your AP = never ending lock #1558

Open Jagakatt opened 1 year ago

Jagakatt commented 1 year ago

Wrong password in portal and you are stuck.

My first post, and I will probably piss some one off because I missed something. My deepest apologies in advance!

Hardware

WiFimanager Branch/Release: Master(?) 2.0.15-rc.1

Esp8266

Hardware: ESP-12e, esp01, esp25

Core Version: No clue... Arduindo IDE 2.0.3..?

Description

Problem description // When starting up in "portal mode" and you enter the portal, click on "Configure WiFi", select your SSID, and enter THE WRONG PASSWORD. // Now you are stuck. A reset (button press) does not help. You have to connect to another network, then close it down do get another try. // Not possible to recover without connecting to another "valid network"

Settings in IDE, STANDARD

Module: NodeMcu, Wemos D1

Additional libraries:

Sketch


// Test, is it a bug if wrong WiFi-AP-password is entered?
// When starting up in "portal mode" and you enter the portal, click on "Configure WiFi", select your SSID, and enter THE WRONG PASSWORD.
// Now you are stuck. A reset (button press) does not help. You have to connect to another network, then close it down do get another try.
// Not possible to recover without connecting to another "valid network"

// Based on: https://github.com/tzapu/WiFiManager/blob/master/examples/NonBlocking/AutoConnectNonBlocking/AutoConnectNonBlocking.ino
// WiFimanager Tzapu 2.0.15-rc.1
// Arduino IDE 2.0
// WEMOS D1 Mini pro ESP8266

#include <WiFiManager.h>  // https://github.com/tzapu/WiFiManager
WiFiManager wm;

void setup() {
  WiFi.mode(WIFI_STA);  // explicitly set mode, esp defaults to STA+AP
  // put your setup code here, to run once:
  Serial.begin(115200);

  //reset settings - wipe credentials for testing
  //wm.resetSettings();

  wm.setConfigPortalBlocking(false);
  wm.setConfigPortalTimeout(60);
  //automatically connect using saved credentials if they exist
  //If connection fails it starts an access point with the specified name
  if (wm.autoConnect("AutoConnectAP", "wwwwwwww")) {
    Serial.println("connected...yeey :)");
  } else {
    Serial.println("Configportal running");
  }
}

String WiFiString;
String previousWiFiString;

void loop() {
  wm.process();
  // put your main code here, to run repeatedly:

  if (WiFi.status() == WL_IDLE_STATUS) {  // when not connected to a network, but powered on
    WiFiString = "WL_IDLE_STATUS 0";
  } else if (WiFi.status() == WL_NO_SSID_AVAIL) {
    WiFiString = "WL_NO_SSID_AVAIL 1 ";
  } else if (WiFi.status() == WL_SCAN_COMPLETED) {
    WiFiString = "WL_SCAN_COMPLETED 2";
  } else if (WiFi.status() == WL_CONNECTED) {
    WiFiString = "WL_CONNECTED 3";
  } else if (WiFi.status() == WL_CONNECT_FAILED) {
    WiFiString = "WL_CONNECT_FAILED 4";
  } else if (WiFi.status() == WL_CONNECTION_LOST) {
    WiFiString = "WL_CONNECTION_LOST 5 ";
  } else if (WiFi.status() == WL_DISCONNECTED) {
    WiFiString = "WL_DISCONNECTED 6 ";
  }

  if (WiFiString != previousWiFiString) {
    Serial.print("WiFi.status                      : ");
    Serial.println(WiFiString);
    previousWiFiString = WiFiString;
  }
}

Debug Messages

/*21:29:22.684 -> {ll��|�l�<�$�c|ǃ��s�#�c��g'�l'o���cp�lrl{lx�n��lĜb'�|���c��gn�dćd`�ng$`'{���o#d�dp�g�;������co�|�c��'o�l`�g'l`o;Ǜ�gc��`s��'c��`�$���d`��g�d*wm:AutoConnect 
21:29:22.877 -> *wm:Connecting to SAVED AP: turbo2
21:29:23.358 -> *wm:connectTimeout not set, ESP waitForConnectResult... 
21:29:26.629 -> *wm:AutoConnect: FAILED 
21:29:26.629 -> *wm:StartAP with SSID:  AutoConnectAP
21:29:28.620 -> *wm:AP IP address: 192.168.4.1
21:29:28.620 -> *wm:Starting Web Portal 
21:29:28.716 -> Configportal running
21:29:28.716 -> WiFi.status                      : WL_IDLE_STATUS 0
21:29:57.195 -> *wm:3 networks found
21:30:41.042 -> *wm:4 networks found
21:30:45.309 -> *wm:4 networks found
21:30:56.658 -> *wm:Connecting to NEW AP: turbo2
21:30:56.787 -> *wm:connectTimeout not set, ESP waitForConnectResult... 
21:31:03.046 -> *wm:[ERROR] Connect to new AP Failed 
21:31:19.638 -> *wm:3 networks found

// Entered the INCORRECT password and saved, and waited...... And nothing. Resetted the device and it comes up in portal mode again. Grrr!

21:32:02.534 -> sd$��|�l�|�d�b|����;�c�c��og�lgn���cp��dsd;lx�o��l��c'�|���c��'o�d��d`�gnl`n{���obd�dp�g�;������co�<�c��o'�$`�no$`gs�ۓo#��`{��o#��`�$Ǐ�$`��g�l*wm:AutoConnect 
21:32:02.728 -> *wm:Connecting to SAVED AP: turbo2
21:32:03.304 -> *wm:connectTimeout not set, ESP waitForConnectResult... 
21:32:09.270 -> *wm:AutoConnect: FAILED 
21:32:09.270 -> *wm:StartAP with SSID:  AutoConnectAP
21:32:11.261 -> *wm:AP IP address: 192.168.4.1
21:32:11.261 -> *wm:Starting Web Portal 
21:32:11.389 -> Configportal running
21:32:11.389 -> WiFi.status                      : WL_IDLE_STATUS 0
21:32:27.628 -> *wm:3 networks found

// Entered the CORRECT password and saved, and waited...... And nothing. Resetted the device and it comes up in portal mode again. Grrr!

21:33:11.574 -> ;ld��|�$�|�d�b<����s�b�#��no�$g'���cp��ds$sdp�g��l��c'�|���b��ng�$��l �no$`'{���ocd�lx�n�{�ܜ���co�<�c��no�d`�no$`'{���gcĒ s��'c��`�$���$`��g�d*wm:AutoConnect 
21:33:11.767 -> *wm:Connecting to SAVED AP: turbo2
21:33:12.246 -> *wm:connectTimeout not set, ESP waitForConnectResult... 
21:33:18.245 -> *wm:AutoConnect: FAILED 
21:33:18.245 -> *wm:StartAP with SSID:  AutoConnectAP
21:33:20.235 -> *wm:AP IP address: 192.168.4.1
21:33:20.235 -> *wm:Starting Web Portal 
21:33:20.363 -> Configportal running
21:33:20.363 -> WiFi.status                      : WL_IDLE_STATUS 0
*/
tablatronix commented 1 year ago

are you SURE you are using that version ? this looks like a very old bug

Jagakatt commented 1 year ago

I just installed thru the library manager in Arduino IDE.

cat library.properties

name=WiFiManager version=2.0.15-rc.1 author=tzapu maintainer=tablatronix sentence=WiFi Configuration manager with web configuration portal for Espressif ESPx boards, by tzapu paragraph=Library for configuring ESP8266/ESP32 modules WiFi credentials and custom parameters at runtime with captive portal. category=Communication url=https://github.com/tzapu/WiFiManager.git architectures=esp8266,esp32 pepe@turbo2:~/Arduino/libraries/WiFiManager$

tablatronix commented 1 year ago

This is what debug_level 3 should look like saving a new password *wm:[1] Connecting to NEW AP

*wm:[2] <- HTTP WiFi save  
*wm:[3] Method: POST
*wm:[3] Sent wifi save page 
*wm:[2] processing save 
*wm:[2] Connecting as wifi client... 
*wm:[3] STA static IP:
*wm:[2] setSTAConfig static ip not set, skipping 
*wm:[1] Connecting to NEW AP: leela
*wm:[3] Using Password: xxxxxxx
*wm:[3] WiFi_enableSTA enable

is your ssid input somehow empty? I do not think there is a check for empty ssid, thats the only thing I can see

Jagakatt commented 1 year ago

Seam to be working as it should. Was fooled by the automatic pre-filled-in SSID in the portal (realize now it's grey and not black text). Looked like it was only the password missing to do the connection. Much headache for nothing but really happy it's working. Sorry for my post. Should I click "Close and Completed" here below? I'm new to this...

Screenshot_20230201-01 Screenshot_20230201-03 Screenshot_20230201-02

tablatronix commented 1 year ago

What browser are you using? the placeholder should also be the value and submitted still, thats odd

Jagakatt commented 1 year ago

Looks like it's the ESP that outputs the SSID in grey if you have a previous successful connection (and now SSID is unavailable). Or if you have a previous unsuccessful connection attempt with incorrect password.

Well it's easy to go around it by tapping on the correct network in the list when you know it. But at least it fooled me when it looked like it was already in place. ;- )

Do not know what browser-components launched in the phone when accessing "Config portal" from the WiFi-setting. But it's the same behavior on the following phones:

Xiaomi Redmi Note 8 Pro Kernel 4.14.141-g95d4269 Model M1906g7g Android 10 QP1A.190711.020 MIUI Global 12.0.8 Chrome: 109.0.5414.117

Doogee S96Pro Doogee-s96pro-EEA-Android10.0-20211116 Chrome: 109.0.5414.86

Samsung Galaxy A5 Android 8.0.0

Doogee s98 Android 12

tablatronix commented 1 year ago

Let me check a few things, if its in grey it should be resbumitted on save, I did not have to reset the AP when changing password so there must be a condition that changes, but perhaps not always working, or not being prefilled correctly sometimes?

I am adding argument debugging ( you can see arguments by turning on esp debugging also )

Project-Exhale commented 1 year ago

I just encountered the same bug, SSID looks prefilled and when saved, the missing SSID results in "Connect to new AP Failed" and ESP32 is locked until restart.

prochazkapeter commented 1 year ago

Hello, I have similar issue. When I enter a bad password in the Configuration Portal it goes into endless loop of (xxxxx) wifi:Set status to INIT. When I reset the ESP32, it goes back to this loop. I have to call resetSettings() to fix this.

Example here: 17:41:41.460 -> wm:AP IP address: 192.168.4.1 17:41:41.460 -> wm:Starting Web Portal 17:41:50.006 -> wm:20 networks found 17:41:57.518 -> wm:Connecting to NEW AP: WB12-2G 17:41:57.611 -> wm:connectTimeout not set, ESP waitForConnectResult... 17:42:04.740 -> E (31317) wifi:Set status to INIT 17:42:04.817 -> E (31376) wifi:Set status to INIT 17:42:04.817 -> E (31402) wifi:Set status to INIT x x 17:42:05.998 -> wm:Connect Wifi, ATTEMPT # 2 of 33 17:42:05.998 -> wm:Connecting to NEW AP: WB12-2G 17:42:05.998 -> wm:connectTimeout not set, ESP waitForConnectResult... 17:42:05.998 -> E (32601) wifi:Set status to INIT 17:42:06.075 -> E (32636) wifi:Set status to INIT 17:42:06.122 -> E (32704) wifi:Set status to INIT

I would imagine, that the connection should fail due to the bad password and create the configuration portal again.

Thank you :-)

tablatronix commented 1 year ago

Thanks! i have no idea what 17:42:05.998 -> E (32601) wifi:Set status to INIT is... hmm

are you all using git or the last release?

chriskinal commented 1 year ago

I have seen that error as well when I turn off the AP the ESP32 is connected to. I was simulating losing connection to the AP while testing my other issue. It seemed to happen randomly with connection losses > 10 seconds.

I think it is coming from the program that is in the Setup() versus WiFiManager. The errors I get from WiFiManager are all prefixed with "wm:' since that is the name of the WiFiManager instance.

tablatronix commented 1 year ago

1563

1540

tablatronix commented 1 year ago

I pushed a release, made it release. It might have a fix for this already

tablatronix commented 1 year ago

Has anyone retested this?

pho3nix06 commented 10 months ago

I am having the same issue, in AP mode when a wrong password is entered, the ESP is stuck, and showing "ESP waitForConnectResult...". And after one minute it is showing "[ERROR] Connect to new AP Failed ".

image

Is there any way that I can print the "wrong password" in serial terminal while the config portal keeping open?

tablatronix commented 10 months ago

Thanks I will test this and see whats going on, sounds like a bug detecting the save as a change.

tablatronix commented 10 months ago

Not sure how to reproduce this bug, for one, I cannot safe the wrong password, as wm does not save on fail by default.. So thats odd.

If I do use the wrong password, I can still just save the new one and no stuck ??

*wm:[SYS] WM version:  v2.0.15-rc.1
*wm:[SYS] Arduino version:  2.0.14
*wm:[SYS] ESP SDK version:  4.4.6.231024
*wm:[SYS] Free heap:        305700
*wm:[SYS] Chip ID: 3245692124
*wm:[SYS] Chip Model: ESP32-S3
.......
[WIFI] WIFI_INFO DEBUG
[WIFI] SAVED: YES
[WIFI] SSID: leela
[WIFI] PASS: wrongpassword
*wm:AutoConnect 
*wm:Connecting to SAVED AP: leela
*wm:connectTimeout not set, ESP waitForConnectResult... 
*wm:AutoConnect: FAILED for  13611 ms
*wm:StartAP with SSID:  WM_AutoConnectAP
*wm:AP IP address: 192.168.4.1
[CALLBACK] configModeCallback fired
*wm:Starting Web Portal 
*wm:5 networks found
*wm:Connecting to NEW AP: leela (RIGHT PASSWORD)
*wm:connectTimeout not set, ESP waitForConnectResult... 
*wm:Connect to new AP [SUCCESS] 
*wm:Got IP Address: 
*wm:192.168.20.254 
[CALLBACK] saveCallback fired
*wm:config portal exiting 
connected...yeey :)
tablatronix commented 10 months ago

You have to enter the SSID, is that what you are talking about? A placeholder does not get submitted in the form, you have to fill out the SSID, you cannot just change the password.

pho3nix06 commented 10 months ago

No, the SSID is automatically getting filled by clicking the SSIDs that's been showing after scan, there is no issue about that. Let me elaborate a bit,

Now my question is, how can I get an error callback(for entering wrong WiFi credentials) after spending 10 seconds of failed attempt while the config portal is still open (while the stack is still running)? In the documentation, there is function setAPCallback() which will return on failed WiFi connection attempt. But it is returning after 5 minutes (setConfigPortalTimeout()).

tablatronix commented 10 months ago

Thats is not the same issue here, also not sure what you mean close and open the browser again, I suggest you open another issue with this question. If you want to close the portal on failures, you can but you have to set breakafterconfig=true, or use a callback. If it fails and the portal is still open, you can still go back to the previous page, but I am not sure if you are using captiveportal or not, this needs a new issue to clearly explain this

tablatronix commented 10 months ago

Also what is 'ERROR scan waiting?' that is not WM..

RFDarter commented 10 months ago

@tablatronix Your recent "fix" in WiFIManagaer.cpp line 1817 if(_ssid = "" && _pass != ""){

made thing a lot worse. I took me a while to finde this mistake.

I guess you meant to write if(_ssid == "" && _pass != ""){

tablatronix commented 10 months ago

thanks, geez, thats the 2nd time, my bad, been working on 3 projects in 5 different languages pushed

pho3nix06 commented 10 months ago

@tablatronix Sure I will open another issue. Regarding the ERROR scan waiting , not sure, I thought this is also from wm. Let me look into this and will update if I find anything.

tablatronix commented 10 months ago

Yeah I definitely have a goal to get the saving flow better worked out but there are so many variables with accounting for captiveportals and ap stability when channel scanning for connects. So getting your info will help me figure out specific use cases

but lets make sure you are actually using this library