[GH-ISSUE #922] Save SSID and PSW #780

Closed
opened 2026-02-28 01:27:00 +03:00 by kerem · 1 comment
Owner

Originally created by @ASLABSIT on GitHub (Aug 11, 2019).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/922

Basic Infos

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)

Description

Problem description
In case of WIFI router down and leater restarted WiFi.SSID() will be empty and WM goes in AP mode.

*WM: [1] AutoConnect
*WM: [2] Connecting as wifi client...
*WM: [1] STA static IP:
*WM: [2] setSTAConfig static ip not set
*WM: [3] WIFI station disconnect
*WM: [1] No saved credentials, skipping wifi ??????
*WM: [2] Connection result: WL_NO_SSID_AVAIL
*WM: [3] lastconxresult: WL_NO_SSID_AVAIL
*WM: [1] AutoConnect: FAILED
*WM: [3] WIFI station disconnect
*WM: [3] WiFi station enable
*WM: [2] Disabling STA
*WM: [2] Enabling AP
*WM: [1] StartAP with SSID: ASlabs
*WM: [2] AP has anonymous access!
*WM: [1] AP IP address: 192.168.4.1

Probably is ESP8266 WiFi issue

I simply SOLVED saving _MYssid and _MYpass end try a new connection.
Function uint8_t WiFiManager::connectWifi(String ssid, String pass)

become:

// @todo refactor this up into seperate functions
// one for connecting to flash , one for new client
// clean up, flow is convoluted, and causes bugs
uint8_t WiFiManager::connectWifi(String ssid, String pass) {
DEBUG_WM(DEBUG_VERBOSE,F("Connecting as wifi client..."));

uint8_t connRes = (uint8_t)WL_NO_SSID_AVAIL;

setSTAConfig();
//@todo catch failures in set_config

// make sure sta is on before begin so it does not call enablesta->mode while persistent is ON ( which would save WM AP state to eeprom !)
if(_cleanConnect) WiFi_Disconnect(); // disconnect before begin, in case anything is hung, this causes a 2 seconds delay for connect
// @todo find out what status is when this is needed, can we detect it and handle it, say in between states or idle_status

// if ssid argument provided connect to that
if (ssid != "") {
wifiConnectNew(ssid,pass);
if(_saveTimeout > 0){
connRes = waitForConnectResult(_saveTimeout); // use default save timeout for saves to prevent bugs in esp->waitforconnectresult loop
}
else {
connRes = waitForConnectResult(0);
}
}
else {
// connect using saved ssid if there is one
if (WiFi_hasAutoConnect()) {
wifiConnectDefault();
connRes = waitForConnectResult();
}
else {
DEBUG_WM(F("No saved credentials, skipping wifi"));
DEBUG_WM(connRes);
}
}

//***** ASLABSIT ******//
// Try with my saved credential

if (connRes == WL_NO_SSID_AVAIL)
{
DEBUG_WM(F("Using MY CONFIG parameter"));

ETS_UART_INTR_DISABLE();
wifi_station_disconnect();
ETS_UART_INTR_ENABLE();

WiFi.begin(_MYssid, _MYpass);
delay(100);
connRes = waitForConnectResult();
DEBUG_WM("MY Connection result: ");
DEBUG_WM(connRes);

}
//***** ASLABSIT ******//

....

_MYssid, _MYpass were previosly saved.

Probably there will be a better way to do that ;-) ....this is my workaround.

Regards.

Originally created by @ASLABSIT on GitHub (Aug 11, 2019). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/922 #### Basic Infos #### 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) ### Description Problem description In case of WIFI router down and leater restarted WiFi.SSID() will be empty and WM goes in AP mode. *WM: [1] AutoConnect *WM: [2] Connecting as wifi client... *WM: [1] STA static IP: *WM: [2] setSTAConfig static ip not set *WM: [3] WIFI station disconnect *WM: [1] No saved credentials, skipping wifi ?????? *WM: [2] Connection result: WL_NO_SSID_AVAIL *WM: [3] lastconxresult: WL_NO_SSID_AVAIL *WM: [1] AutoConnect: FAILED *WM: [3] WIFI station disconnect *WM: [3] WiFi station enable *WM: [2] Disabling STA *WM: [2] Enabling AP *WM: [1] StartAP with SSID: ASlabs *WM: [2] AP has anonymous access! *WM: [1] AP IP address: 192.168.4.1 Probably is ESP8266 WiFi issue I simply SOLVED saving _MYssid and _MYpass end try a new connection. Function uint8_t WiFiManager::connectWifi(String ssid, String pass) become: // @todo refactor this up into seperate functions // one for connecting to flash , one for new client // clean up, flow is convoluted, and causes bugs uint8_t WiFiManager::connectWifi(String ssid, String pass) { DEBUG_WM(DEBUG_VERBOSE,F("Connecting as wifi client...")); uint8_t connRes = (uint8_t)WL_NO_SSID_AVAIL; setSTAConfig(); //@todo catch failures in set_config // make sure sta is on before `begin` so it does not call enablesta->mode while persistent is ON ( which would save WM AP state to eeprom !) if(_cleanConnect) WiFi_Disconnect(); // disconnect before begin, in case anything is hung, this causes a 2 seconds delay for connect // @todo find out what status is when this is needed, can we detect it and handle it, say in between states or idle_status // if ssid argument provided connect to that if (ssid != "") { wifiConnectNew(ssid,pass); if(_saveTimeout > 0){ connRes = waitForConnectResult(_saveTimeout); // use default save timeout for saves to prevent bugs in esp->waitforconnectresult loop } else { connRes = waitForConnectResult(0); } } else { // connect using saved ssid if there is one if (WiFi_hasAutoConnect()) { wifiConnectDefault(); connRes = waitForConnectResult(); } else { DEBUG_WM(F("No saved credentials, skipping wifi")); DEBUG_WM(connRes); } } //***** ASLABSIT ******// // Try with my saved credential if (connRes == WL_NO_SSID_AVAIL) { DEBUG_WM(F("Using MY CONFIG parameter")); ETS_UART_INTR_DISABLE(); wifi_station_disconnect(); ETS_UART_INTR_ENABLE(); WiFi.begin(_MYssid, _MYpass); delay(100); connRes = waitForConnectResult(); DEBUG_WM("MY Connection result: "); DEBUG_WM(connRes); } //***** ASLABSIT ******// .... _MYssid, _MYpass were previosly saved. Probably there will be a better way to do that ;-) ....this is my workaround. Regards.
kerem closed this issue 2026-02-28 01:27:01 +03:00
Author
Owner

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

If your credentials are not being saved you have a memory problem, erase your flash
this is completely unnecessary as it is already the supposed to be the default behavior.

<!-- gh-comment-id:520244297 --> @tablatronix commented on GitHub (Aug 11, 2019): If your credentials are not being saved you have a memory problem, erase your flash this is completely unnecessary as it is already the supposed to be the default behavior.
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#780
No description provided.