Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: No Return of status WRONG_PASSWORD during WiFi Connect #8233

Open
5 of 6 tasks
hasenradball opened this issue Jul 23, 2021 · 17 comments
Open
5 of 6 tasks

[BUG]: No Return of status WRONG_PASSWORD during WiFi Connect #8233

hasenradball opened this issue Jul 23, 2021 · 17 comments

Comments

@hasenradball
Copy link
Contributor

hasenradball commented Jul 23, 2021

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: [ESP-12]
  • Core Version: [latest git hash or date]
  • Development Env: [Arduino IDE]
  • Operating System: [Windows|]

Settings in IDE

  • Module: [Wemos D1 mini]
  • Flash Mode: []
  • Flash Size: [4MB]
  • lwip Variant: []
  • Reset Method: [ck|nodemcu]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mhz|]
  • Upload Using: [SERIAL]
  • Upload Speed: [115200)

Problem Description

When try to provoke the return off info WL_WRONG_PASSWORD this does not happen.
sketch is provided.

MCVE Sketch

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "wifi_secrets.h"

constexpr int LED {5};

wl_status_t get_wifi_status(void) {
  // keep in mind
  /*
    WL_NO_SHIELD        = 255,   // for compatibility with WiFi Shield library
    WL_IDLE_STATUS      = 0,
    WL_NO_SSID_AVAIL    = 1,
    WL_SCAN_COMPLETED   = 2,
    WL_CONNECTED        = 3,
    WL_CONNECT_FAILED   = 4,
    WL_CONNECTION_LOST  = 5,
    WL_WRONG_PASSWORD   = 6,
    WL_DISCONNECTED     = 7
  */
  wl_status_t status = WiFi.status();
  if (status == WL_NO_SHIELD) {
     Serial.println(F("\n WiFI.status == NO_SHIELD"));
  }
  else if (status == WL_IDLE_STATUS) {
    Serial.println(F("\n WiFI.status == IDLE_STATUS"));
  }
  else if (status == WL_NO_SSID_AVAIL) {
    Serial.println(F("\n WiFI.status == NO_SSID_AVAIL"));
  }
  else if (status == WL_SCAN_COMPLETED) {
    Serial.println(F("\n WiFI.status == SCAN_COMPLETED"));
  }
  else if (status == WL_CONNECTED) {
    Serial.println(F("\n WiFI.status == CONNECTED"));
  }
  else if (status == WL_CONNECT_FAILED) {
    Serial.println(F("\n WiFI.status == CONNECT_FAILED"));
  }
  else if (status == WL_CONNECTION_LOST) {
    Serial.println(F("\n WiFI.status == CONNECTION_LOST"));
  }
  else if (status == WL_WRONG_PASSWORD) {
    Serial.println(F("\n WiFI.status == WRONG_PASSWORD"));
  }
  else if (status == WL_DISCONNECTED) {
    Serial.println(F("\n WiFI.status == DISCONNECTED"));
  }
  else {
     Serial.println(F("\n No appropriate Status available!"));
  }
  return status;
}


bool wifi_connect(const char *_SSID, const char * _PASSWORD, const char *_hostname = nullptr){
  Serial.printf("Set WiFi mode to WIFI_STA - %d\n", WiFi.mode(WIFI_STA));
  if (_hostname != nullptr) WiFi.hostname(_hostname);
  // Warte auf Verbindung
  WiFi.begin(_SSID, "test");
  while (WiFi.status() != WL_CONNECTED) {
    // Status function from API
    uint8_t status_API = wifi_station_get_connect_status(); 
    Serial.printf(" 1 - Wifi status API:\t%d\n", status_API);
    
    // Status from Arduino core
    wl_status_t status_CORE = WiFi.status(); 
    Serial.printf(" 2 - Wifi status core:\t%d\n", status_CORE);

    Serial.printf(" 3 - Wifi status:\t%d\n", get_wifi_status());
    
    if ((status_API == STATION_WRONG_PASSWORD) || (status_CORE == WL_WRONG_PASSWORD)){
      return true;
    }
    delayMicroseconds(100);
  }
  return true;
}
  /*
   * if (WiFi.waitForConnectResult() == WL_CONNECTED) {
    Serial.printf(" Wifi status: %d\n", get_wifi_status());
    Serial.println("\n Connection - success! <<<");
    return true;
  }
  else {
    Serial.printf(" Wifi status: %d\n", WiFi.status());
    Serial.printf(" Wifi status: %d\n", get_wifi_status());
    Serial.println("\n Connection - failed! <<<");
    return false;
  }
}
*/

void setup() {
  Serial.begin(115200);
  pinMode(LED, OUTPUT);
  while (!Serial) yield();
  Serial.print("\n\n");
  WiFi.printDiag(Serial);
  //WiFi.setAutoReconnect(false);
  WiFi.setAutoConnect(false);
  WiFi.persistent(false);

  time_t tic {millis()};
  digitalWrite(LED, HIGH);
  if (wifi_connect(SSID, PASSWORD)) {
    Serial.printf("time until connect: %0.3f s\n", (millis() - tic)/1000.0);
    WiFi.disconnect();
    digitalWrite(LED, LOW);
    delay(1000);
  }
}


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

}

Debug Messages

Debug messages go here
@hasenradball hasenradball changed the title No Return of InfoWRONG_PASSWORD during WiFi Connect [BUG]: No Return of InfoWRONG_PASSWORD during WiFi Connect Jul 23, 2021
@hasenradball hasenradball changed the title [BUG]: No Return of InfoWRONG_PASSWORD during WiFi Connect [BUG]: No Return of statusWRONG_PASSWORD during WiFi Connect Jul 23, 2021
@hasenradball hasenradball changed the title [BUG]: No Return of statusWRONG_PASSWORD during WiFi Connect [BUG]: No Return of status WRONG_PASSWORD during WiFi Connect Jul 23, 2021
@hasenradball
Copy link
Contributor Author

See the following shot for example...

15 min until the ESP raises WRONG_PASSWORD

grafik

@mcspr
Copy link
Collaborator

mcspr commented Jul 23, 2021

Does it have different results replacing

- WiFi.setAutoConnect(false);
+ WiFi.setAutoConnect(true);

?
(maybe also reconnect)

edit: is this related to the #7432?

@hasenradball
Copy link
Contributor Author

I will try

@hasenradball
Copy link
Contributor Author

Does it have different results replacing

- WiFi.setAutoConnect(false);
+ WiFi.setAutoConnect(true);

?
(maybe also reconnect)

edit: is this related to the #7432?

see also this Note:

grafik

@hasenradball
Copy link
Contributor Author

With the setting WiFi.setAutoConnect(true); no positive changes --> after nearly 60 min detection of WRONG_PASSWORD.
So is this Emum not usable.

 WiFI.status == DISCONNECTED
 3 - Wifi status:	7
 1 - Wifi status API:	1
 2 - Wifi status core:	7

 WiFI.status == DISCONNECTED
 3 - Wifi status:	7
 1 - Wifi status API:	1
 2 - Wifi status core:	6

 WiFI.status == WRONG_PASSWORD
 3 - Wifi status:	6
time until connect: 3498.974 s

@hasenradball
Copy link
Contributor Author

With the setting WiFi.setAutoReConnect(true); no positive changes --> after nearly 60 min detection of WRONG_PASSWORD.


 WiFI.status == DISCONNECTED
 3 - Wifi status:       7
 1 - Wifi status API:   1
 2 - Wifi status core:  7

 WiFI.status == DISCONNECTED
 3 - Wifi status:       7
 1 - Wifi status API:   1
 2 - Wifi status core:  7

 WiFI.status == DISCONNECTED
 3 - Wifi status:       7
 1 - Wifi status API:   1
 2 - Wifi status core:  7

 WiFI.status == DISCONNECTED
 3 - Wifi status:       7
 1 - Wifi status API:   2
 2 - Wifi status core:  6

 WiFI.status == WRONG_PASSWORD
 3 - Wifi status:       6
time until connect: 3522.949 s

@mcspr
Copy link
Collaborator

mcspr commented Jul 24, 2021

looking at the event handler, it does not see the invalid psk reason as well

int reason{0};

// insert this in the connect-check loop
void dump_reason() {
  if (reason > 0) {
    int copy{reason};
    reason = 0;
    Serial.printf(" 4 - WiFi disconnect event: %d\n", copy);
  }
}

void setup() {
  static auto disconnected = WiFi.onStationModeDisconnected([](const auto& event) {
    reason = event.reason;
  });

  ... the rest ...
}
 4 - WiFi disconnect event: 2

while on the ap box, hostapd logs psk mismatch

hostapd: wlan1-1: AP-STA-POSSIBLE-PSK-MISMATCH xx:xx:xx:xx:xx:xx

also note the invalid psk test should be at least 8bytes long i.e. something like testtest

@hasenradball
Copy link
Contributor Author

hasenradball commented Jul 24, 2021

Do I have it implemented Correctly?

bool wifi_connect(const char *_SSID, const char * _PASSWORD, const char *_hostname = nullptr){
  Serial.printf("Set WiFi mode to WIFI_STA - %d\n", WiFi.mode(WIFI_STA));
  if (_hostname != nullptr) WiFi.hostname(_hostname);
  // Warte auf Verbindung
  WiFi.begin(_SSID, "testtest");
  while (WiFi.status() != WL_CONNECTED) {
    dump_reason();
    // Status function from API
    uint8_t status_API = wifi_station_get_connect_status(); 
    Serial.printf(" 1 - Wifi status API:\t%d\n", status_API);
    
    // Status from Arduino core
    wl_status_t status_CORE = WiFi.status(); 
    Serial.printf(" 2 - Wifi status core:\t%d\n", status_CORE);

    Serial.printf(" 3 - Wifi status:\t%d\n", get_wifi_status());
    
    if ((status_API == STATION_WRONG_PASSWORD) || (status_CORE == WL_WRONG_PASSWORD)){
      return true;
    }
    delayMicroseconds(100);
  }
  return true;
}
void setup() {
    static auto disconnected = WiFi.onStationModeDisconnected([](const auto& event) {
    reason = event.reason;
  });
  Serial.begin(115200);
  pinMode(LED, OUTPUT);
  while (!Serial) yield();
  Serial.print("\n\n");
  WiFi.printDiag(Serial);
  WiFi.setAutoReconnect(false);
  WiFi.setAutoConnect(false);
  WiFi.persistent(false);

  time_t tic {millis()};
  digitalWrite(LED, HIGH);
  if (wifi_connect(SSID, PASSWORD)) {
    Serial.printf("time until connect: %0.3f s\n", (millis() - tic)/1000.0);
    WiFi.disconnect();
    digitalWrite(LED, LOW);
    delay(1000);
  }
}

@hasenradball
Copy link
Contributor Author

@mcspr your event will not be print in my code, maybee I implemented it wrong?

@hasenradball
Copy link
Contributor Author

the reason seems to be always 0

@mcspr
Copy link
Collaborator

mcspr commented Jul 25, 2021

as I modified it to run - https://gist.github.com/mcspr/c7b40fea7dd1323c11ad45b08103b979
different led and wifi_connect func receives the actual real SSID and invalid PASSWORD ("testtesttest")

@hasenradball
Copy link
Contributor Author

Thanks for Your Update :-)

Here is the result:


 WiFI.status == DISCONNECTED
 1 - Wifi status API:	1
 2 - Wifi status core:	7
 3 - Wifi status:	7

 WiFI.status == DISCONNECTED
 1 - Wifi status API:	1
 2 - Wifi status core:	7
 3 - Wifi status:	7

 WiFI.status == DISCONNECTED
 1 - Wifi status API:	1
 2 - Wifi status core:	7
 3 - Wifi status:	7

 WiFI.status == DISCONNECTED
 1 - Wifi status API:	1
 2 - Wifi status core:	7
 3 - Wifi status:	7

 WiFI.status == DISCONNECTED
 1 - Wifi status API:	1
 2 - Wifi status core:	7
 3 - Wifi status:	7

 WiFI.status == DISCONNECTED
 1 - Wifi status API:	1
 2 - Wifi status core:	7
 3 - Wifi status:	7

 WiFI.status == DISCONNECTED
 1 - Wifi status API:	1
 2 - Wifi status core:	7
 3 - Wifi status:	7

 WiFI.status == DISCONNECTED
 1 - Wifi status API:	1
 2 - Wifi status core:	7
 3 - Wifi status:	7

 WiFI.status == WRONG_PASSWORD
 1 - Wifi status API:	2
 2 - Wifi status core:	6
 3 - Wifi status:	6
 4 - reason:	204
time until connect: 5427.494 s

after 5400 s the WRONG PASSWORD rises... :-(

@hasenradball
Copy link
Contributor Author

how could we proceed now?

@mcspr
Copy link
Collaborator

mcspr commented Jul 27, 2021

from the examples above, imo it's a duplicate of the #7432

  • there is no direct 'wrong password' wifi event, only authentication related issues, so idk what it actually means from the connection manager point of view
  • wifi_station_get_connect_status() can't really be trusted to report any issues asap, until something breaks internally / some timeout only-known-to-the-sdk expires. it does not report wrong password for neither short passphrase, same as wifi_station_set_config_current() btw, or after the auth error disconnection event
  • disabling reconnect may leave the device in STATION_CONNECTING state for a long time, unless some external timeout is tracking the connection attempt and it won't report STATION_CONNECT_FAIL for a very long time

@hasenradball
Copy link
Contributor Author

So you mean the introduced Enum WRONG_PASSWORD in core 3.0.0 has no intention to get the info of a wrong password within a few ms?

@mcspr
Copy link
Collaborator

mcspr commented Jul 28, 2021

this might be a historical feature that was never implemented / broken? one mention of it is here - tzapu/WiFiManager#528 (comment)
although, @tablatronix might have a better explanation about the STATION_WRONG_PASSWORD and when it actually happens, since #4152 and #7652 don't go into much details
and there's also espressif/ESP8266_NONOS_SDK#218

@CodeCanna
Copy link

Good to see its not a me problem, I was going crazy with this. I get 4 as the result of WiFi.status() when I purposefully enter the wrong password, simply a connection failed error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants