scanNetworks erases stored wifi credentials
- Dominant language
- C++
- Stars
- 16.7k
- Forks
- 13.1k
- PR merge metrics
- No merged PRs in 30d
Description
### Basic Infos
A call to scanNetworks erases the current wifi credentials if the ESP can't find the currently set network.
This has the downstream effect that WiFiManager deletes your current WiFi settings if you go to the Wifi configuration screen but then change your mind and don't select a new network.
#### Hardware
Hardware: ESP-8266 / Wemos D1 mini
### Description
In
```
Arduino/libraries/ESP8266WiFi/src/ESP8266WiFiScan.cpp
```
line 78
```
int status = wifi_station_get_connect_status();
if(status != STATION_GOT_IP && status != STATION_IDLE) {
WiFi.disconnect(false);
}
```
If the return code from wifi_station_get_connect_status is (for example) STATION_NO_AP_FOUND, because it can't currently see the configured AP, then it calls WiFi.disconnect, which starts off by
resetting the current WiFi credentials to null and then stores the settings.
I'm not sure whether the right answer is to only reset the WiFi credentials under certain exceptional situations (I'm don't know what those would be), OR, just comment out that line.
That's what I've done in the library, and it all works fine - scan works fine, and nothing else seems to be harmed.
So, I'd propose deleting that bit of code.
Or maybe a call to wifi_station_disconnect(); was intended?
Anyway, it seems to work fine without it, and leaving it in causes unnecessary clearing of the WiFi credentials.
### Settings in IDE
Module: Wemos D1 R2 & mini
Flash Size: 4MB
CPU Frequency: 80Mhz
Flash Mode: ????
Flash Frequency: ????
Upload Using: SERIAL
Reset Method: ????
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.