Advertisement
mikroavr

scan_wifi_esp32

Sep 28th, 2022
1,617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "WiFi.h"
  2.  
  3. void setup() {
  4.   Serial.begin(115200);
  5.  
  6.   // Set WiFi to station mode and disconnect from an AP if it was previously connected
  7.   WiFi.mode(WIFI_STA);
  8.   WiFi.disconnect();
  9.   delay(100);
  10.  
  11.   Serial.println("Setup done");
  12. }
  13.  
  14. void loop() {
  15.   Serial.println("scan start");
  16.  
  17.   // WiFi.scanNetworks will return the number of networks found
  18.   int n = WiFi.scanNetworks();
  19.   Serial.println("scan done");
  20.   if (n == 0) {
  21.       Serial.println("no networks found");
  22.   } else {
  23.     Serial.print(n);
  24.     Serial.println(" networks found");
  25.     for (int i = 0; i < n; ++i) {
  26.       // Print SSID and RSSI for each network found
  27.       Serial.print(i + 1);
  28.       Serial.print(": ");
  29.       Serial.print(WiFi.SSID(i));
  30.       Serial.print(" (");
  31.       Serial.print(WiFi.RSSI(i));
  32.       Serial.print(")");
  33.       Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
  34.       delay(10);
  35.     }
  36.   }
  37.   Serial.println("");
  38.  
  39.   // Wait a bit before scanning again
  40.   delay(5000);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement