[GH-ISSUE #1439] getWiFiIsSaved returning wrong value #1233

Open
opened 2026-02-28 01:29:09 +03:00 by kerem · 6 comments
Owner

Originally created by @OekoSolveMG on GitHub (Jun 22, 2022).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1439

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();
}
Originally created by @OekoSolveMG on GitHub (Jun 22, 2022). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1439 ### 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. ```cpp 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** ```cpp 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** ```cpp 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(); } ```
Author
Owner

@murmeltier08 commented on GitHub (Jan 31, 2023):

Same problem here. Please fix it :)

<!-- gh-comment-id:1410914651 --> @murmeltier08 commented on GitHub (Jan 31, 2023): Same problem here. Please fix it :)
Author
Owner

@tablatronix commented on GitHub (Jan 31, 2023):

This was removed already from the code

<!-- gh-comment-id:1411121063 --> @tablatronix commented on GitHub (Jan 31, 2023): This was removed already from the code
Author
Owner

@murmeltier08 commented on GitHub (Feb 1, 2023):

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

<!-- gh-comment-id:1411505653 --> @murmeltier08 commented on GitHub (Feb 1, 2023): but it not working before autoconnect. i need to check this flag in the beginning of the code.
Author
Owner

@tablatronix commented on GitHub (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

<!-- gh-comment-id:1412196012 --> @tablatronix commented on GitHub (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
Author
Owner

@Vitallyz commented on GitHub (Feb 25, 2023):

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!

<!-- gh-comment-id:1444979810 --> @Vitallyz commented on GitHub (Feb 25, 2023): 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!
Author
Owner

@tablatronix commented on GitHub (Mar 23, 2023):

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

<!-- gh-comment-id:1480431715 --> @tablatronix commented on GitHub (Mar 23, 2023): 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 in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1233
No description provided.