ESP32 could not associate with my AP in event site.

blues27
Posts: 1
Joined: Fri Mar 04, 2022 5:35 am

ESP32 could not associate with my AP in event site.

Postby blues27 » Sat Mar 05, 2022 6:08 am

Hello all,

Could any one tell the reason why ESP32 could not associate with my WiFi AP in the event site?
I want to know the limitation of the number of APs that ESP32 can scan to find the specific SSID.

When I took my device using ESP32 as a main processer to an event site where there are enormous number of WiFi routers(Access Point)(maybe more than 100 APs around my device including with my AP), my device could not get IP address from DHCP server running in my AP.
I downloaded the following code through Arduino IDE in order to check if ESP32 could find AP.
In most case, WiFi.scanNetworks() returned "4 - 15", but following "WiFi.SSID" does not return my AP's ssid.
When ESP32 found my AP's ssid, WiFi.status returned "WL_CONNECTED WL_DISCONNECTED" or "WL_NO_SSID_AVAIL" and
never returned to "WL_CONNECTED".
After the event ended (that's means many AP's power were OFF), the ESP32 could reach my AP and get IP Address.

Does any one know why ESP32 could not access my AP ?

Is there any reason why WiFi.scanNetworks() returns only small bumber?

  1. #include "WiFi.h"
  2.  
  3. const char *ssid = "ssidofap";
  4. const char *pass = "password";
  5.  
  6. void mydelay(int msec)
  7. {
  8.   vTaskDelay(msec / portTICK_RATE_MS);      
  9. }
  10.  
  11. void wifi_connection(void)
  12. {
  13.   do{
  14.     if(WiFi.status() == WL_CONNECTED)
  15.       break;
  16.      
  17.     mydelay(100);
  18.     WiFi.disconnect();
  19.     mydelay(100);
  20.    
  21.     WiFi.begin(ssid, pass);
  22.     Serial.println("");
  23.  
  24.     for(int i=0;i<120;i++){
  25.       mydelay(500);
  26.       Serial.print(".");
  27.       Serial.print(i);
  28.       Serial.print(".");
  29.       int wifist = WiFi.status() ;
  30.      
  31.       switch(wifist){
  32.         case WL_IDLE_STATUS : Serial.println("WL_IDLE_STATUS");break;
  33.         case WL_NO_SSID_AVAIL : Serial.println("WL_NO_SSID_AVAIL");break;
  34.         case WL_SCAN_COMPLETED : Serial.println("WL_SCAN_COMPLETED");break;
  35.         case WL_CONNECTED : Serial.println("WL_CONNECTED");break;
  36.         case WL_CONNECT_FAILED : Serial.println("WL_CONNECT_FAILED");break;
  37.         case WL_CONNECTION_LOST : Serial.println("WL_CONNECTION_LOST");break;
  38.         case WL_DISCONNECTED : Serial.println("WL_DISCONNECTED");break;
  39.       }
  40.  
  41.       if(WiFi.status() == WL_NO_SSID_AVAIL) {
  42.         Serial.println("WL_NO_SSID_AVAIL, reconnection begins");
  43.         mydelay(500);
  44.  
  45. //        break;
  46.       }
  47.  
  48.       if(WiFi.status() == WL_CONNECTED){
  49.         Serial.println("WL_CONNECTED");
  50.         break;
  51.       }
  52.     }
  53.        
  54.   }while(WiFi.status() != WL_CONNECTED);
  55.  
  56.   if(WiFi.status() == WL_CONNECTED) {
  57.     Serial.println("");
  58.     Serial.print("Connected to ");
  59.     Serial.println(ssid);
  60.     Serial.print("IP address: ");
  61.     Serial.println(WiFi.localIP());
  62.     return ;
  63.   }
  64.   mydelay(500);
  65. }
  66.  
  67. void setup()
  68. {
  69.     Serial.begin(115200);
  70.  
  71.     WiFi.mode(WIFI_STA);
  72.     WiFi.disconnect();
  73.     delay(100);
  74.  
  75.     Serial.println("Setup done");
  76.  
  77. }
  78.  
  79. void loop()
  80. {
  81.     Serial.println("scan start");
  82.  
  83.     int n = WiFi.scanNetworks();
  84.     Serial.println("scan done");
  85.     if (n == 0) {
  86.         Serial.println("no networks found");
  87.     } else {
  88.         Serial.print(n);
  89.         Serial.println(" networks found");
  90.         for (int i = 0; i < n; ++i) {
  91.             Serial.print(i + 1);
  92.             Serial.print(": ");
  93.             Serial.print(WiFi.SSID(i));
  94.             Serial.print(": ");
  95.             if(WiFi.SSID(i)==ssid)
  96.               wifi_connection();
  97.  
  98.             Serial.print(": ");
  99.  
  100.             Serial.print(" (");
  101.             Serial.print(WiFi.RSSI(i));
  102.             Serial.print(")");
  103.             Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
  104.             delay(10);
  105.         }
  106.     }
  107.     Serial.println("");
  108.  
  109.     delay(500);
  110. }

Bast regards.

Who is online

Users browsing this forum: Chipset68 and 61 guests