Wifi Scan Failure in High-Density Environment

Good morning, evening or afternoon,

I've been experimenting with the scan networks example from the WifiS3 library for the Arduino Rev 4 Wifi. At home, the program works perfect but within a university building comprised of a WPA2 Enterprise network, the program gets permanently stuck on the command:

numSsid = WiFi.scanNetworks();

My guess would be that a high density network of routers is too much for the ESP-32-S3-MINI-1 to handle but since I am brand new to WIFI programming this is just a guess. Funnily enough the only location in which the scan will complete is in the elevator.

Has anyone else encountered this issue or might there be a work-around for example by modifying the WifiS3 library.

Thanks in advance.

Okay very excited because I somehow managed to solve this issue myself after pouring over the WiFiS3 library for hours and hours.

The key difference with the WiFiS3.h library is that there is no set limit for the number of SSID's listed in a network scan. (to the best of my knowledge)

Now within an environment like a public library, uni building or office where there are well beyond 30 networks, it appears that the poor Arduino Rev 4 cannot cope and therefore becomes stuck on the function:

numSsid = WiFi.scanNetworks();

However, this can be solved by changing the following section of code in the Wifi.cpp file of the library:


/* -------------------------------------------------------------------------- */
int8_t CWifi::scanNetworks() {
/* -------------------------------------------------------------------------- */
   modem.begin();

   modem.avoid_trim_results();
   modem.read_using_size();

   access_points.clear();
   string res;

   vector<string> aps;
   if(modem.write(string(PROMPT(_WIFISCAN)),res,CMD(_WIFISCAN))) {

      split(aps, res, string("\r\n"));
       for(uint16_t i = 0;(i < aps.size() && i < 30); i++) {
         CAccessPoint ap;
         vector<string> tokens;
         split(tokens, aps[i], string("|"));
         if(tokens.size() >= 5) {
            ap.ssid            = tokens[0];
            ap.bssid           = tokens[1];
            macStr2macArray(ap.uint_bssid, ap.bssid.c_str());
            ap.rssi            = tokens[2];
            ap.channel         = tokens[3];
            ap.encryption_mode = tokens[4];
            access_points.push_back(ap);
         }
      } 
   }

   return (int8_t)access_points.size();
}

the key takeaway here is that I have limited the number of networks listed to 30:

** for(uint16_t i = 0;(i < aps.size() && i < 30); i++) **

I believe 30 or 40 is the maximum number of networks that the Rev 4 can scan before encountering an error.

Anyway I hope this helps anyone that might encounter this issue in the future.

1 Like

WiFi.cpp (18.5 KB)

I'll add that if anyone still has issues scanning for networks within a wifi congested environment, it might be that the RAM requirements of the sketch are conflicting with the network scan, to solve this simply the limit the number of networks to be scanned, for example, this edited wifi.cpp file I have attached limits the number of networks to be scanned to 10. Any questions about this I'll try keep tabs in the forum.

In short, the larger the sketch, the higher the likelihood that a large network scan will cause problems.