scanNetworks in ESP8266WiFi.h take too much time

i am facing a problem with the function scan Networks i takes at least 2.5 second and that is a lot for my project , i need to reduce that time to a maximum delay of 0.5 second but it seems that i cant find a way to do that ,can you please help me to do it.

i need to reduce that time to at least .5 second

If you want the function to take at least 0.5 seconds, and it currently takes 2.5 seconds, it seems to me that your goal is met.

No i meant maximum 0.5 second ,my bad sorry :-[ :-[

We'll obviously need to see your code, and know something about the libraries you are using, and your network.

How often do you need to scan for networks? Most people do it once, and then connect to the proper one.

in my code i need at least 2 scans per 1 second ,i need to send the RSSI values of a selected Access points to a server , to make a positioning system work , and if it took more than 2 second to even scan my system will have a wrong data ,i need the scan every time so i can tell that the position is changed based on the RSSI values , so i need more than one scan and i need them fast .

Scanning for all available access points, and scanning for a specific one, are not the same thing. Still can't see your code.

By the way, I hope you understand that the RSSI value is only very poorly correlated to distance.

this is what i am trying to do after this code i just send the data to server Ap1,Ap2 contains the BSSID of my Access points

int numSsid = WiFi.scanNetworks();

int sgAp1=-110;int sgAp2=-110;int sgAp3=-110;int sgAp4=-110;

for (int thisNet = 0; thisNet < numSsid; thisNet++) {
String name=WiFi.BSSIDstr(thisNet);
if(name==Ap1)
{ sgAp1=WiFi.RSSI(thisNet);
}
else if(name==Ap2)
{ sgAp2=WiFi.RSSI(thisNet);
}
else if(name==Ap3)
{ sgAp3=WiFi.RSSI(thisNet);
}
else if(name==Ap4)
{ sgAp4=WiFi.RSSI(thisNet);
}

}
numAp1= sgAp1*(-1);
numAp2=sgAp2*(-1);
numAp3=sgAp3*(-1);
numAp4=sgAp4*(-1);
String data="";
data = “ap1=”+a+"&ap2="+String(numAp2)+"&ap3="+String(numAp3)+"&ap4="+String(numAp4);

So, you KNOW the names of the 4 networks. Why is it necessary to scan?

i need to refresh the RSSI values. is there another way to do so??

i need to refresh the RSSI values. is there another way to do so??

Isn't that what WiFi.RSSI() does? Or does it just return the last value obtained by scanNetworks()? I know that scanNetworks() does a lot; maybe you can extract just the stuff you need it to do.

lamees: i am facing a problem with the function scan Networks i takes at least 2.5 second and that is a lot for my project , i need to reduce that time to a maximum delay of 0.5 second but it seems that i cant find a way to do that ,can you please help me to do it.

Well, the ESP8266 must scan channel by channel and display what it finds. That is not going to be overly fast any way you do it.

The link below shows how to scan for one SSID and if found, prints the RSSI. You can easily adapt this for 4 AP and select the strongest.

http://www.esp8266.com/viewtopic.php?f=29&t=10888#p51060

Ray

mrburnette: The link below shows how to scan for one SSID and if found, prints the RSSI. You can easily adapt this for 4 AP and select the strongest.

http://www.esp8266.com/viewtopic.php?f=29&t=10888#p51060

Good, except that it contains:  int n = WiFi.scanNetworks();

It looks like the ESP8266 can scan for selected SSID, BSSID, or channel. I suspect that setting all of the configuration options to 0 is causing the library to scan everything:

 struct scan_config config;
 config.ssid = 0;
 config.bssid = 0;
 config.channel = 0;
 config.show_hidden = show_hidden;
 if(wifi_station_scan(&config, reinterpret_cast<scan_done_cb_t>(&ESP8266WiFiScanClass::_scanDone))) {
 ESP8266WiFiScanClass::_scanComplete = false;
 ESP8266WiFiScanClass::_scanStarted = true;

 if(ESP8266WiFiScanClass::_scanAsync) {
 delay(0); // time for the OS to trigger the scan
 return WIFI_SCAN_RUNNING;
 }

PaulS: Isn't that what WiFi.RSSI() does? Or does it just return the last value obtained by scanNetworks()? I know that scanNetworks() does a lot; maybe you can extract just the stuff you need it to do.

WiFi.RSSI() give me the last saved RSSI for specific index or network , can you please suggest how can i extract just the RSSI , i cant find a way to do that . thank you

mrburnette: Well, the ESP8266 must scan channel by channel and display what it finds. That is not going to be overly fast any way you do it.

The link below shows how to scan for one SSID and if found, prints the RSSI. You can easily adapt this for 4 AP and select the strongest.

http://www.esp8266.com/viewtopic.php?f=29&t=10888#p51060

Ray

put i need the scan for BSSID, do you know how ? thank you

johnwasser:
It looks like the ESP8266 can scan for selected SSID, BSSID, or channel. I suspect that setting all of the configuration options to 0 is causing the library to scan everything:

 struct scan_config config;

config.ssid = 0;
config.bssid = 0;
config.channel = 0;
config.show_hidden = show_hidden;
if(wifi_station_scan(&config, reinterpret_cast<scan_done_cb_t>(&ESP8266WiFiScanClass::_scanDone))) {
ESP8266WiFiScanClass::_scanComplete = false;
ESP8266WiFiScanClass::_scanStarted = true;

if(ESP8266WiFiScanClass::_scanAsync) {
delay(0); // time for the OS to trigger the scan
return WIFI_SCAN_RUNNING;
}

i tried to pass the BSSID as a parameter did not work !!
do you suggest somthing else ?
thank you

Did you pass a 6-byte array with the binary value? I think that is what it is expecting.

johnwasser:
Did you pass a 6-byte array with the binary value? I think that is what it is expecting.

i tried a pointer and it kept asking me for default value
like this

int8_t ESP8266WiFiScanClass::scanNetworks2(bool async, bool show_hidden ,uint8_t* &BSSID) {
if(ESP8266WiFiScanClass::_scanStarted) {
return WIFI_SCAN_RUNNING;
}

ESP8266WiFiScanClass::_scanAsync = async;

WiFi.enableSTA(true);

int status = wifi_station_get_connect_status();
if(status != STATION_GOT_IP && status != STATION_IDLE) {
WiFi.disconnect(false);
}

scanDelete();

struct scan_config config;
config.ssid = 0;
config.bssid = BSSID;
config.channel = 0;
config.show_hidden = show_hidden;
if(wifi_station_scan(&config, reinterpret_cast<scan_done_cb_t>(&ESP8266WiFiScanClass::_scanDone))) {
ESP8266WiFiScanClass::_scanComplete = false;
ESP8266WiFiScanClass::_scanStarted = true;

if(ESP8266WiFiScanClass::_scanAsync) {
delay(0); // time for the OS to trigger the scan
return WIFI_SCAN_RUNNING;
}

esp_yield();
return ESP8266WiFiScanClass::_scanCount;
} else {
return WIFI_SCAN_FAILED;
}

}

johnwasser: Did you pass a 6-byte array with the binary value? I think that is what it is expecting.

i manged to pass the BSSID and the search only returns one Access point but the delay is the same . it did not help.