Post links and attach files for documentation here, also chat about these docs freely

User avatar
By Sppm
#93450 Hello. My apologies if I am doing this wrong but my first time posting in this environment and not sure what or how to do.

I am using an ESP8266 and programing it with the Arduino ASP. While using the ESP8266WiFi.h functionality I find that all the sample code segments work for scanning WiFi networks but if in my code after I have already connected to a network if I attempt to do a scanNetworks() I get no results. The desire for this is that after a network has been selected and connected to the user might want to change the ssid they are connecting to. I have not found a way to get this to work.

Thinking that I need to turn off the WiFi and restart it again I have tried calling WiFi.mode(WIFI_OFF) and then WiFi.mode(WIFI_STA) (everything I have looked at seems to indicate that the wifi system needs to be in this state to do a wifiScan). I then call WiFi.scanNetworks() but get a return of zero networks. When I call this same code segment:

String scanWiFiNets() {
availableNets = "";
WiFi.disconnect();
WiFi.mode(WIFI_OFF);
WiFi.mode(WIFI_STA);
int n = WiFi.scanNetworks(false, true);
for (int i = 0; i < n; i++) {
availableNets += WiFi.SSID(i) + + " (" + WiFi.RSSI(i) + ")" + // Print SSID and RSSI for each network found
((WiFi.encryptionType(i) == AUTH_OPEN)?" Unprotected": " Pwd"
" required") + "\n";
Serial.println(WiFi.SSID(i));
}
return availableNets;
}

from my setup routines before I actually connect to a wifi network it works fine and returns the expected number of wifi networks. When I call it after I have logged into a ssid I always get a return of zero wifi nets found.

I am sure there is something I need to set to something before I run the wifi scan but alas, I am stumped figuring out what.

Any help would be greatly appreciated.

Thank you....