[GH-ISSUE #918] Storing SSID, IP #775

Open
opened 2026-02-28 01:27:00 +03:00 by kerem · 8 comments
Owner

Originally created by @esp8 on GitHub (Jul 30, 2019).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/918

Hardware

WiFimanager Branch/Release:

  • Master
  • Development

Esp8266/Esp32:

  • ESP8266
  • ESP32

Hardware: ESP-12e, esp01, esp25

  • ESP01
  • ESP12 E/F/S (nodemcu, wemos, feather)
  • Other

ESP Core Version: 2.4.0, staging

  • 2.3.0
  • 2.4.0
  • staging (master/dev) 2.5.0

Description

I am playing with example AutoConnectWithStaticIP.ino . I changed only IP address. The problem is with storing parameters . When I try to save new ssid informations, It seems that the parameters are not written in to the memory.
Example AutoConnect.ino works OK. If I upload AutoConnectWithStaticIP.ino after storing ssid and password with AutoConnect.ino example (and not erase the memory) than esp connects to my network, but the parameters are fixed. It is not possible to change values. On the log output it is all normal. Any idea?

Debug Messages

*WM: WiFi save
*WM: static ip
*WM: 192.168.1.18
*WM: static gateway
*WM: 192.168.1.1
*WM: static netmask
*WM: 255.255.255.0
*WM: Sent wifi save page
*WM: Connecting to new AP
*WM: Connecting as wifi client...
*WM: Custom STA IP/GW/Subnet
*WM: 192.168.1.18
*WM: Already connected. Bailing out.
connected...yeey :)
local ip
192.168.1.18
*WM: freeing allocated params!
Originally created by @esp8 on GitHub (Jul 30, 2019). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/918 #### Hardware **WiFimanager Branch/Release:** - [ ] Master - [x] Development **Esp8266/Esp32:** - [x] ESP8266 - [ ] ESP32 **Hardware: ESP-12e, esp01, esp25** - [ ] ESP01 - [x] ESP12 E/F/S (nodemcu, wemos, feather) - [ ] Other **ESP Core Version: 2.4.0, staging** - [ ] 2.3.0 - [ ] 2.4.0 - [x] staging (master/dev) 2.5.0 ### Description I am playing with example AutoConnectWithStaticIP.ino . I changed only IP address. The problem is with storing parameters . When I try to save new ssid informations, It seems that the parameters are not written in to the memory. Example AutoConnect.ino works OK. If I upload AutoConnectWithStaticIP.ino after storing ssid and password with AutoConnect.ino example (and not erase the memory) than esp connects to my network, but the parameters are fixed. It is not possible to change values. On the log output it is all normal. Any idea? ### Debug Messages ``` *WM: WiFi save *WM: static ip *WM: 192.168.1.18 *WM: static gateway *WM: 192.168.1.1 *WM: static netmask *WM: 255.255.255.0 *WM: Sent wifi save page *WM: Connecting to new AP *WM: Connecting as wifi client... *WM: Custom STA IP/GW/Subnet *WM: 192.168.1.18 *WM: Already connected. Bailing out. connected...yeey :) local ip 192.168.1.18 *WM: freeing allocated params! ```
Author
Owner

@tablatronix commented on GitHub (Jul 30, 2019):

parameters are not stored anywhere, you have to save them yourself.

<!-- gh-comment-id:516577378 --> @tablatronix commented on GitHub (Jul 30, 2019): parameters are not stored anywhere, you have to save them yourself.
Author
Owner

@esp8 commented on GitHub (Jul 31, 2019):

hmm.
In example AutoConnect.ino when I am in AP mode and save SSID and password, these parameters are stored somewhere, because after cycling power esp connects to network.

If i do the same with AutoConnectWithStaticIP.ino SSID and password is lost.
I tried on 3 nodemcu v1.0 and the situation is always the same.

<!-- gh-comment-id:516717524 --> @esp8 commented on GitHub (Jul 31, 2019): hmm. In example AutoConnect.ino when I am in AP mode and save SSID and password, these parameters are stored somewhere, because after cycling power esp connects to network. If i do the same with AutoConnectWithStaticIP.ino SSID and password is lost. I tried on 3 nodemcu v1.0 and the situation is always the same.
Author
Owner

@tablatronix commented on GitHub (Jul 31, 2019):

oh ok, hmm well esp does the saving for wifi creds, might be something wrong with those examples, you tested both on the same hardware? Sometimes flash needs to be erased as it gets corrupted.

I will take a look.

<!-- gh-comment-id:516832815 --> @tablatronix commented on GitHub (Jul 31, 2019): oh ok, hmm well esp does the saving for wifi creds, might be something wrong with those examples, you tested both on the same hardware? Sometimes flash needs to be erased as it gets corrupted. I will take a look.
Author
Owner

@wvsbsp commented on GitHub (Aug 11, 2019):

I'm currently developing a project, where i am saving SSID, password, mqtt-server and topic into a config-file in the SPIFFS. I had the problem of getting the SSID and Password out of the WifiManager.

My solution to this was to edit the wifimanager.cpp, Lines 350 ff.
Here two getter-functions are commented out, which are String WiFiManager::getSSID() and String WiFiManager::getPassword().
Also the if-clause mae problems, so my getter-function just looks like this:
String WiFiManager::getSSID() {
/*if (_ssid == "") {
DEBUG_WM(F("Reading SSID"));
_ssid = WiFi.SSID(); <<<<=== this seems to be a problem in the original code
DEBUG_WM(F("SSID: "));
DEBUG_WM(_ssid);
}*/
return _ssid;
}

Then add the prototypes in wifimanager.h and you're done. In my project i'm reading the custom values and SSID and password like this:
strcpy(mqtt_server, custom_mqtt_server.getValue());
strcpy(mqtt_port, custom_mqtt_port.getValue());
strcpy(mqtt_topic, custom_mqtt_topic.getValue());
// SSID and Passwort from WifiManager
String sTemp=wifiManager.getSSID();
if(sTemp != "") strcpy(ssid, sTemp.c_str()); // don't overwrite with empty sting
sTemp=wifiManager.getPassword();
if(sTemp != "") strcpy(pass, sTemp.c_str()); // don't overwrite with empty sting
Serial.println("New values: ");
Serial.println(ssid);
Serial.println(pass);
Serial.println(mqtt_server);
Serial.println(mqtt_topic);
// save configuration in SPIFFS
saveConfig();

I would like to see the getter-functions reactivated in the next version of WifiManager (which is a superb library!)

Edit: unfortunately, code formatting doesn't work properly, no new lines :-(

<!-- gh-comment-id:520250685 --> @wvsbsp commented on GitHub (Aug 11, 2019): I'm currently developing a project, where i am saving SSID, password, mqtt-server and topic into a config-file in the SPIFFS. I had the problem of getting the SSID and Password out of the WifiManager. My solution to this was to edit the wifimanager.cpp, Lines 350 ff. Here two getter-functions are commented out, which are String WiFiManager::getSSID() and String WiFiManager::getPassword(). Also the if-clause mae problems, so my getter-function just looks like this: ` String WiFiManager::getSSID() {` ` /*if (_ssid == "") {` ` DEBUG_WM(F("Reading SSID"));` ` _ssid = WiFi.SSID(); <<<<=== this seems to be a problem in the original code` ` DEBUG_WM(F("SSID: "));` ` DEBUG_WM(_ssid);` ` }*/` ` return _ssid;` ` }` Then add the prototypes in wifimanager.h and you're done. In my project i'm reading the custom values and SSID and password like this: ` strcpy(mqtt_server, custom_mqtt_server.getValue());` ` strcpy(mqtt_port, custom_mqtt_port.getValue());` ` strcpy(mqtt_topic, custom_mqtt_topic.getValue());` ` // SSID and Passwort from WifiManager ` ` String sTemp=wifiManager.getSSID();` ` if(sTemp != "") strcpy(ssid, sTemp.c_str()); // don't overwrite with empty sting` ` sTemp=wifiManager.getPassword();` ` if(sTemp != "") strcpy(pass, sTemp.c_str()); // don't overwrite with empty sting` ` Serial.println("New values: ");` ` Serial.println(ssid);` ` Serial.println(pass);` ` Serial.println(mqtt_server);` ` Serial.println(mqtt_topic);` ` // save configuration in SPIFFS` ` saveConfig();` I would like to see the getter-functions reactivated in the next version of WifiManager (which is a superb library!) Edit: unfortunately, code formatting doesn't work properly, no new lines :-(
Author
Owner

@tablatronix commented on GitHub (Aug 11, 2019):

The esp already provides these

<!-- gh-comment-id:520254791 --> @tablatronix commented on GitHub (Aug 11, 2019): The esp already provides these
Author
Owner

@wvsbsp commented on GitHub (Aug 11, 2019):

The esp already provides these

what do you mean? I'm currently using WifiManager Version 0.14.0 and i had to remove the comment and add prototypes to make the getter-functions working. Is it meant to be like that or is there a newer version of WifiManager with those functions enabled?
Or do you mean the ESP is storing the Wifi-credentials? In my case, i want to have a system where i can control and save the AP the system is connecting to when WifiManager is not involved. In that case i need some source to fill the values for ssid and password before calling
WiFi.begin(ssid, pass);
The board should only connect with one network, but that has to be configurable. After reset, i'm waiting for a button-press to start the wifiManager. If the button is not pressed, the system has to connect to the SSID that was previousely configured and saved in wifiManager.

<!-- gh-comment-id:520262926 --> @wvsbsp commented on GitHub (Aug 11, 2019): > The esp already provides these what do you mean? I'm currently using WifiManager Version 0.14.0 and i had to remove the comment and add prototypes to make the getter-functions working. Is it meant to be like that or is there a newer version of WifiManager with those functions enabled? Or do you mean the ESP is storing the Wifi-credentials? In my case, i want to have a system where i can control and save the AP the system is connecting to when WifiManager is not involved. In that case i need some source to fill the values for ssid and password before calling `WiFi.begin(ssid, pass);` The board should only connect with one network, but that has to be configurable. After reset, i'm waiting for a button-press to start the wifiManager. If the button is not pressed, the system has to connect to the SSID that was previousely configured and saved in wifiManager.
Author
Owner

@tablatronix commented on GitHub (Aug 12, 2019):

the ESP stores credentials itself, wifimanager does not handle it.

looks in development branch, i added a helper getter


String WiFiManager::WiFi_SSID(){
  #ifdef ESP8266
    return WiFi.SSID();
  #elif defined(ESP32)
    //@todo , workaround only when not connected
    wifi_config_t conf;
    esp_wifi_get_config(WIFI_IF_STA, &conf);
    return String(reinterpret_cast<const char*>(conf.sta.ssid));
  #endif
}

<!-- gh-comment-id:520446616 --> @tablatronix commented on GitHub (Aug 12, 2019): the ESP stores credentials itself, wifimanager does not handle it. looks in development branch, i added a helper getter ```C++ String WiFiManager::WiFi_SSID(){ #ifdef ESP8266 return WiFi.SSID(); #elif defined(ESP32) //@todo , workaround only when not connected wifi_config_t conf; esp_wifi_get_config(WIFI_IF_STA, &conf); return String(reinterpret_cast<const char*>(conf.sta.ssid)); #endif } ```
Author
Owner

@tablatronix commented on GitHub (Aug 12, 2019):

https://github.com/tzapu/WiFiManager/issues/887

<!-- gh-comment-id:520447366 --> @tablatronix commented on GitHub (Aug 12, 2019): https://github.com/tzapu/WiFiManager/issues/887
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#775
No description provided.