Skip to content
New issue

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

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

Already on GitHub? # to your account

[Question]: return enum WRONG_Password (ESP8266WIFISTA.cpp) #8228

Open
5 of 6 tasks
hasenradball opened this issue Jul 21, 2021 · 8 comments
Open
5 of 6 tasks

[Question]: return enum WRONG_Password (ESP8266WIFISTA.cpp) #8228

hasenradball opened this issue Jul 21, 2021 · 8 comments

Comments

@hasenradball
Copy link
Contributor

hasenradball commented Jul 21, 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-12E]
  • Core Version: [core 3.0.1]
  • Development Env: [Arduino IDE]
  • Operating System: [Windows]

Settings in IDE

  • Module: [Wemos D1 mini]
  • Flash Mode: [qio|dio|other]
  • Flash Size: [4MB]
  • lwip Variant: [v1.4|v2 Lower Memory|Higher Bandwidth]
  • Reset Method: [ck|nodemcu]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mhz]
  • Upload Using: [SERIAL]
  • Upload Speed: [115200]

Problem Description

Hello is it here better to return the Status 6 == WRONG_PASSWORD?

int passphraseLen = passphrase == nullptr ? 0 : strlen(passphrase);
if(passphraseLen > 64) {
// fail passphrase too long!
return WL_CONNECT_FAILED;
}

@d-a-v
Copy link
Collaborator

d-a-v commented Jul 21, 2021

Yes. Would you be ready to create a pull-request for this ?

@hasenradball
Copy link
Contributor Author

I will do a PR for this 😉

@hasenradball
Copy link
Contributor Author

Have You seen my post in Gitter chat?

@d-a-v
Copy link
Collaborator

d-a-v commented Jul 21, 2021

Have You seen my post in Gitter chat?

You have many :) There's always a reason when no one answer to a particular post. If the issue is real/persistent, posting a new entry in the issue tracker like you did is OK and better because is stays visible and opened until one has time to understand and eventually answer.
One could say that you deleted the issue template, and you did, but providing a solution to an issue is, I dare to think, a valid exception.

@hasenradball
Copy link
Contributor Author

Hi sorry added the the template and filled out :-)

@hasenradball
Copy link
Contributor Author

@hasenradball
Copy link
Contributor Author

hasenradball commented Jul 21, 2021

Hi I also recognized if using waitForConnectResult --> it returns also no WL_WRONG_PASWORD;

Because it returns -1!!!
And this is per default WL_Disconnected

Could we return the real status instead on -1?

--> then it should come also WL_WRONG_PASWORD

int8_t ESP8266WiFiSTAClass::waitForConnectResult(unsigned long timeoutLength) {
    //1 and 3 have STA enabled
    if((wifi_get_opmode() & 1) == 0) {
        return WL_DISCONNECTED;
    }
    // if probing doesn't trip, this yields
    using oneShotYieldMs = esp8266::polledTimeout::timeoutTemplate<false, esp8266::polledTimeout::YieldPolicy::YieldOrSkip>;
    oneShotYieldMs timeout(timeoutLength); // number of milliseconds to wait before returning timeout error
    while(!timeout) {
        if(status() != WL_DISCONNECTED) {
            return status();
        }
    }
    return -1; // -1 indicates timeout
}

@hasenradball
Copy link
Contributor Author

I tried to get the status WL_WRONG_PASSWORD by using the folllowing test code (see below), but giving a wrong password does not result in Wifi.status() == WL_WRONG_PASSWORD why???

Does the NOTE has an impact on this?

grafik

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

constexpr const char *SSID {"SSID"};
constexpr const char *PASSWORD {"PASSWD"};


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, nullptr);
  while (WiFi.status() != WL_CONNECTED) {
     Serial.printf(" 1 - Wifi status: %d\n", wifi_station_get_connect_status());
     Serial.printf(" 2 - Wifi status: %d\n", WiFi.status());
     Serial.printf(" 3 - Wifi status: %d\n", get_wifi_status());
     delay(500);
  }
  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);
  while (!Serial) yield();
  Serial.print("\n\n");
  WiFi.setAutoReconnect(false);
  WiFi.setAutoConnect(false);
  WiFi.persistent(false);

  time_t tic {micros()};
  if (wifi_connect(SSID, PASSWORD)) {
    Serial.printf("time until connect: %lld µs\n", (micros() - tic));
    delay(500);
    WiFi.disconnect();
  }
}


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

}

@hasenradball hasenradball changed the title [Question]: return enum WRONG_Passowrd (ESP8266WIFISTA.cpp) [Question]: return enum WRONG_Password (ESP8266WIFISTA.cpp) Jul 21, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants