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

getWiFiIsSaved returning wrong value #1439

Open
OekoSolveMG opened this issue Jun 22, 2022 · 6 comments
Open

getWiFiIsSaved returning wrong value #1439

OekoSolveMG opened this issue Jun 22, 2022 · 6 comments
Labels
bug Validated BUG Priority

Comments

@OekoSolveMG
Copy link

OekoSolveMG commented Jun 22, 2022

Basic Infos

Hardware

WiFimanager Branch / Release: v2.0.11-beta
Esp8266 / Esp32: ESP32
Hardware: M5 Stack Core 1
Core Version: 2.4.0, staging

Description

When the WiFi has not been completly initalized needs some time WiFi_SSID has some trash data in conf.sta.ssid, which then gets converted into a String meaning the String isn't empty. Causing getWiFiIsSaved to return true because the ssid isn't empty even tough there isn't any data saved.

Underlying Problem

I debugged some more and the problem seems to be that the esp_wifi_get_config() method always returns ESP_ERR_WIFI_NOT_INIT (WiFi driver was not installed by esp_wifi_init).

This seems to be the problem becuase the autoConnect only initalizes the WiFiManager if the isWiFiSaved() method returns true. This method can't return true tough until WiFi has been initalized.

I tried to call WiFi.begin(); before attempting to reconnect. This will fix the issue because the esp has now initalized the wifi configuration.

Serial log

Attempts to connect to the WiFi with saved credentials even tough there are none.

WifiIsSaved: True // <--- True even tough it shouldn't be, new device with completly cleared nvs / file system.
[  1704][E][WiFiSTA.cpp:322] begin(): connect failed! 0x300a

Simple fix

Instead of always returning the data converted into a string, which might cause issues see current code below:

WiFiManager.cpp / 3602

if (persistent){
    wifi_config_t conf;
    esp_wifi_get_config(WIFI_IF_STA, &conf);
    return String(reinterpret_cast<const char*>(conf.sta.ssid));
}

The library should instead check if getting the configuration was successfull in the first place and if not return an empty string. Similar to how it returns the value if the boolean flag persistent isn't true.

WiFiManager.cpp / 3602

if (persistent){
    wifi_config_t conf;
    if (esp_wifi_get_config(WIFI_IF_STA, &conf) == ESP_OK) {
        return String(reinterpret_cast<const char*>(conf.sta.ssid));
    }
    return String();
}
@tablatronix tablatronix added the bug Validated BUG label Aug 31, 2022
@murmeltier08
Copy link

Same problem here. Please fix it :)

@tablatronix
Copy link
Collaborator

This was removed already from the code

@murmeltier08
Copy link

but it not working before autoconnect. i need to check this flag in the beginning of the code.

@tablatronix
Copy link
Collaborator

tablatronix commented Feb 1, 2023

ahh yeah its not working at the moment I need to add wifiinit code, I was testing how to do it without causing delays in boot connect..

The easiest way is to just init wifi yourself in your code add a WiFi.mode(WIFI_STA); at the beginning. Another option is maybe we could read it directly from flash, but that changes now and then and would be a pita

esp32 IDF changed how this all works and its annoying

@Vitallyz
Copy link

Hi! Is there any alternative way I can check if the drive is going to try to connect using the existing wifi config or if it will enter AP mode?

Or is there a way to know that we are going to enter (or entered) AP mode? Trying to show some info on the display of my device.

Thanks!

@tablatronix
Copy link
Collaborator

Still thinking of how to fix this, now that the fatal wifi connect bugs in ESP seem to be fixed I can test wifiinit and try to optimize any connection delays from any change I make

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

No branches or pull requests

4 participants