Using ESP32 version 1.0.4 on development branch.
After successful config, calling wifiManager.getWiFiPass(true) consistently returns
an empty string.
Code:
preferences.putString(ATTR_WIFI_SSID, wifiManager.getWiFiSSID(true /*persistent*/));
preferences.putString(ATTR_WIFI_PASS, wifiManager.getWiFiPass(true /*persistent*/));
Serial.printf("wifiManager id: %s value: %s\n", ATTR_WIFI_SSID, preferences.getString(ATTR_WIFI_SSID).c_str());
Serial.printf("**BUG** wifiManager id: %s value: %s\n", ATTR_WIFI_PASS, preferences.getString(ATTR_WIFI_PASS).c_str());
Serial.printf("**BUG** wifiManager id: %s value: %s\n", ATTR_WIFI_PASS, wifiManager.getWiFiPass(true).c_str());
Serial.printf("**BUG** wifiManager id: %s value: %s\n", ATTR_WIFI_PASS, wifiManager.getWiFiPass(false).c_str());
Output:
07:07:26.627 -> wifiManager id: wifi_ssid value: exampleSSID
07:07:26.627 -> **BUG** wifiManager id: wifi_pass value:
07:07:26.627 -> **BUG** wifiManager id: wifi_pass value:
07:07:26.627 -> **BUG** wifiManager id: wifi_pass value:
07:07:26.627 -> id: wifi_pass value: SuperSecret valueLen: 40 label: ssid password (to be saved)
07:07:26.627 -> wifiManager parameters saved as preferences
if you have a stack dump decode it:
N/A
----------------------------- Remove above -----------------------------
WiFimanager Branch/Release:
Esp8266/Esp32:
Hardware: ESP-12e, esp01, esp25
ESP Core Version: 2.4.0, staging
wifiManager.getWiFiPass(true); OR wifiManager.getWiFiPass(false);
are not returning the SSID password configured.
N/A
Additional libraries:
N/A
N/A
Are you calling this after wifi has been init? Or is connected?
Are you calling this after wifi has been init? Or is connected?
Correct. I'm calling it _after_ wifi manager portal was successful in configuring a
ssid with password.
Not sure if this is relevant here, but I'm _NOT_ using wifiManager.autoConnect();
Instead I am using wifiManager.startConfigPortal(); only.
So you are checking this after saving or something?
Cause wifi does not start automatically on esp32
So you are checking this after saving or something?
Cause wifi does not start automatically on esp32
Yes. I invoke wifiManager.startConfigPortal() and procedd with configuring ssid and pass.
All goes well and the function returns as expected. Right after that, I attempt to get the
value of the ssid and the password configured. The ssid returns the right value, but the
password returns empty.
That is what I'm trying to show here: https://github.com/flavio-fernandes/persistWifiSetting/commit/5ad667b862638722c2ee032105ed32c535aa1ce7#diff-05a1eb158f7a5066b9b6d066b4ca593eR109-R112
@flavio-fernandes @tablatronix
add to wifimanager.ccp
String WiFiManager::getSSID() {
if (_ssid == "") {
DEBUG_WM(F("Reading SSID"));
_ssid = WiFi.SSID();
DEBUG_WM(F("SSID: "));
DEBUG_WM(_ssid);
}
return _ssid;
}
String WiFiManager::getPassword() {
if (_pass == "") {
DEBUG_WM(F("Reading Password"));
_pass = WiFi.psk();
DEBUG_WM("Password: " + _pass);
DEBUG_WM(_pass);
}
return _pass;
}
then in wifimanager.h add
String getSSID();
String getPassword();
arduino code
WiFiManager wifiManager;
wifiManager.autoConnect("Hello Word");
Serial.println(getSSID());
Serial.println(getPassword());
here you have the return of ssid and password
No clue it works for me
*WM: [2] disconnect configportal
*WM: [2] restoring usermode STA
*WM: [2] wifi status: WL_CONNECTED
*WM: [2] wifi mode: STA
*WM: [1] config portal exiting
Mode: STA
Channel: 6
SSID (5): Shawn
Passphrase (8): 12345678
BSSID set: 0
YES
SSID: Shawn
PASS: 12345678
Ill probably need more info, like is it actually connecting?
No clue it works for me
*WM: [2] disconnect configportal *WM: [2] restoring usermode STA *WM: [2] wifi status: WL_CONNECTED *WM: [2] wifi mode: STA *WM: [1] config portal exiting Mode: STA Channel: 6 SSID (5): Shawn Passphrase (8): 12345678 BSSID set: 0 YES SSID: Shawn PASS: 12345678Ill probably need more info, like is it actually connecting?
Thanks for trying. Yes, it connects fine and it works as well for me. BUT....
If you call wifiManager.getWiFiPass(false); I''m assuming that you would
expect to see 12345678 but you may get an empty string. Can you confirm?
@flavio-fernandes @tablatronix
add to wifimanager.ccp
wifiManager.autoConnect("Hello Word");
Serial.println(getSSID());
Serial.println(getPassword());here you have the return of ssid and password
Thank you @gauix4 , what you mentioned here worked for me!
I made these 2 changes to try out what you proposed:
And the function returned the password configured! Note I did not have any issues with
the ssid, just the password.
So I don't really know what to do from here, as it seems that the password I expected is just not what it is implemented.
What do you propose? Is this a legit bug? I am okay closing it if that is not important enough.
18:37:56.530 -> *WM: [2] <- HTTP WiFi save
18:37:56.530 -> *WM: [3] Method: POST
18:37:56.530 -> *WM: [2] Parameters
18:37:56.530 -> *WM: [2] --------------------
18:37:56.530 -> *WM: [2] wifi_pass: SuperSecret
18:37:56.530 -> *WM: [2] --------------------
18:37:56.530 -> *WM: [3] Sent wifi save page
18:37:56.530 -> *WM: [2] process connect
18:37:58.564 -> *WM: [2] Connecting as wifi client...
18:37:58.564 -> *WM: [1] STA static IP:
18:37:58.564 -> *WM: [2] setSTAConfig static ip not set
18:37:58.564 -> *WM: [3] WIFI station disconnect
18:37:58.564 -> *WM: [1] CONNECTED:
18:37:58.564 -> *WM: [1] Connecting to NEW AP: exampleSSID
18:37:58.564 -> *WM: [3] Using Password: SuperSecret
18:37:58.564 -> *WM: [3] WiFi station enable
18:37:58.564 -> *WM: [1] connectTimeout not set, ESP waitForConnectResult...
18:37:59.070 -> *WM: [2] Connection result: WL_CONNECTED
18:37:59.070 -> *WM: [3] lastconxresult: WL_CONNECTED
18:37:59.070 -> *WM: [1] Connect to new AP [SUCCESS]
18:37:59.070 -> *WM: [1] Got IP Address:
18:37:59.070 -> *WM: [1] 192.168.10.120
18:37:59.070 -> *WM: [2] disconnect configportal
18:38:00.064 -> *WM: [2] restoring usermode NULL
18:38:00.100 -> *WM: [2] wifi status: Unknown
18:38:00.100 -> *WM: [2] wifi mode: NULL
18:38:00.100 -> *WM: [1] config portal exiting
18:38:00.100 -> wifiManager id: wifi_ssid value: exampleSSID
18:38:00.100 -> **BUG** wifiManager id: wifi_pass value:
18:38:00.100 -> **BUG** wifiManager id: wifi_pass value:
18:38:00.100 -> **BUG** wifiManager id: wifi_pass value:
18:38:00.100 -> **HACKING** wifiManager getPassword value: SuperSecret
18:38:00.100 -> id: wifi_pass value: SuperSecret valueLen: 40 label: ssid password (to be saved)
18:38:00.100 -> wifiManager parameters saved as preferences
18:38:05.123 -> ets Jun 8 2016 00:22:57
18:38:05.123 ->
I did not test with false, but false does nothing for esp32
psk() is literally the same exact code in wm
String WiFiManager::WiFi_psk(bool persistent) const {
#ifdef ESP8266
struct station_config conf;
if(persistent) wifi_station_get_config_default(&conf);
else wifi_station_get_config(&conf);
char tmp[65]; //psk is 64 bytes hex => plus null term
memcpy(tmp, conf.password, sizeof(conf.password));
tmp[64] = 0; //null term in case of 64 byte psk
return String(reinterpret_cast<char*>(tmp));
#elif defined(ESP32)
// only if wifi is init
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
return String();
}
wifi_config_t conf;
esp_wifi_get_config(WIFI_IF_STA, &conf);
return String(reinterpret_cast<char*>(conf.sta.password));
#endif
}
18:38:00.064 -> *WM: [2] restoring usermode NULL
18:38:00.100 -> *WM: [2] wifi status: Unknown
18:38:00.100 -> *WM: [2] wifi mode: NULL
18:38:00.100 -> *WM: [1] config portal exiting
hmm
wifimanager restores the wifi mode that it was at in your sketch, Your mode is WIFI_OFF
if you call autoconnect we change this automatically, you are not calling it. You will need to set a mode in your sketch in setup, as esp32 does not automatically do this like esp8266. Also as in wm v.0 as it was buggy and clobbered your settings. development now works properly with persistent and will let you go back to your previous "current" wifi settings(non persistent)
Now there might still be a bug, have you tried restarting and then starting wifi or just starting wifi after saving ? and see if it was stored, if its persistent it should then work, unless there is a bug causing saves to not be persistent, but there is not that I know of
psk() is literally the same exact code in wm
No. Sorry for the confusion. In my case _pass is not "" so psk() is not used at all.
What makes it work is the fact the value I was expecting was stored in _pass.
Make sense?
https://github.com/flavio-fernandes/WiFiManager/commit/497364330f065b84fef17383884c1294d2dc6943#diff-bfe0a2d15de63f0ead6d59ff54dd518eR2475
That is just a variable, not the saved password
@flavio-fernandes can you drop your code here i take a look and test
arduino code:
Serial.print(_ssid);
Serial.print(_pass);
add in .ccp
void WiFiManager::handleWifiSave() {
DEBUG_WM(F("WiFi save"));
//SAVE/connect here
_ssid = server->arg("s").c_str();
_pass = server->arg("p").c_str();
DEBUG_WM (_ssid);
DEBUG_WM (_pass);
@flavio-fernandes can you drop your code here i take a look and test
hello @gauix4 . My code is here:
https://github.com/flavio-fernandes/persistWifiSetting
You can look at branch issueWifiPass for how I reproduce it.
I am good dealing with this issue now, thanks to your help and @tablatronix .
Much appreciated.