diff --git a/libraries/WiFi/examples/WiFiScan/README.md b/libraries/WiFi/examples/WiFiScan/README.md index 7d70735f2176a82e326a23f6b8223defb239f759..188ae7453a085a5e51aa8965c479ecfc80422504 100644 --- a/libraries/WiFi/examples/WiFiScan/README.md +++ b/libraries/WiFi/examples/WiFiScan/README.md @@ -2,12 +2,12 @@ This example demonstrates how to use the WiFi library to scan available WiFi networks and print the results. -# Supported Targets +## Supported Targets Currently this example supports the following targets. -| Supported Targets | ESP32 | ESP32-S2 | ESP32-C3 | -| ----------------- | ----- | -------- | -------- | +| Supported Targets | ESP32 | ESP32-S2 | ESP32-C3 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | ## How to Use Example @@ -25,25 +25,16 @@ Currently this example supports the following targets. ## Example/Log Output ``` -ets Jul 29 2019 12:21:46 - -rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) -configsip: 0, SPIWP:0xee -clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 -mode:DIO, clock div:1 -load:0x3fff0030,len:1412 -load:0x40078000,len:13400 -load:0x40080400,len:3672 -entry 0x400805f8 Setup done -scan start -scan done +Scan start +Scan done 17 networks found -1: IoTNetwork (-62)* -2: WiFiSSID (-62)* -3: B3A7992 (-63)* -4: WiFi (-63) -5: IoTNetwork2 (-64)* +Nr | SSID | RSSI | CH | Encryption + 1 | IoTNetwork | -62 | 1 | WPA2 + 2 | WiFiSSID | -62 | 1 | WPA2-EAP + 3 | B3A7992 | -63 | 6 | WPA+WPA2 + 4 | WiFi | -63 | 6 | WPA3 + 5 | IoTNetwork2 | -64 | 11 | WPA2+WPA3 ... ``` diff --git a/libraries/WiFi/examples/WiFiScan/WiFiScan.ino b/libraries/WiFi/examples/WiFiScan/WiFiScan.ino index 5d11fbb69267353a9aea2c8e3c75dd44a8559842..12827e88ed0ec5ac25508cf1fabfcd4cba65746b 100644 --- a/libraries/WiFi/examples/WiFiScan/WiFiScan.ino +++ b/libraries/WiFi/examples/WiFiScan/WiFiScan.ino @@ -1,7 +1,7 @@ /* * This sketch demonstrates how to scan WiFi networks. - * The API is almost the same as with the WiFi Shield library, - * the most obvious difference being the different file you need to include: + * The API is based on the Arduino WiFi Shield library, but has significant changes as newer WiFi functions are supported. + * E.g. the return value of `encryptionType()` different because more modern encryption is supported. */ #include "WiFi.h" @@ -9,7 +9,7 @@ void setup() { Serial.begin(115200); - // Set WiFi to station mode and disconnect from an AP if it was previously connected + // Set WiFi to station mode and disconnect from an AP if it was previously connected. WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100); @@ -19,30 +19,68 @@ void setup() void loop() { - Serial.println("scan start"); + Serial.println("Scan start"); - // WiFi.scanNetworks will return the number of networks found + // WiFi.scanNetworks will return the number of networks found. int n = WiFi.scanNetworks(); - Serial.println("scan done"); + Serial.println("Scan done"); if (n == 0) { Serial.println("no networks found"); } else { Serial.print(n); Serial.println(" networks found"); + Serial.println("Nr | SSID | RSSI | CH | Encryption"); for (int i = 0; i < n; ++i) { // Print SSID and RSSI for each network found - Serial.print(i + 1); - Serial.print(": "); - Serial.print(WiFi.SSID(i)); - Serial.print(" ("); - Serial.print(WiFi.RSSI(i)); - Serial.print(")"); - Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*"); + Serial.printf("%2d",i + 1); + Serial.print(" | "); + Serial.printf("%-32.32s", WiFi.SSID(i).c_str()); + Serial.print(" | "); + Serial.printf("%4d", WiFi.RSSI(i)); + Serial.print(" | "); + Serial.printf("%2d", WiFi.channel(i)); + Serial.print(" | "); + switch (WiFi.encryptionType(i)) + { + case WIFI_AUTH_OPEN: + Serial.print("open"); + break; + case WIFI_AUTH_WEP: + Serial.print("WEP"); + break; + case WIFI_AUTH_WPA_PSK: + Serial.print("WPA"); + break; + case WIFI_AUTH_WPA2_PSK: + Serial.print("WPA2"); + break; + case WIFI_AUTH_WPA_WPA2_PSK: + Serial.print("WPA+WPA2"); + break; + case WIFI_AUTH_WPA2_ENTERPRISE: + Serial.print("WPA2-EAP"); + break; + case WIFI_AUTH_WPA3_PSK: + Serial.print("WPA3"); + break; + case WIFI_AUTH_WPA2_WPA3_PSK: + Serial.print("WPA2+WPA3"); + break; + case WIFI_AUTH_WAPI_PSK: + Serial.print("WAPI"); + break; + default: + Serial.print("unknown"); + } + Serial.println(); delay(10); } } Serial.println(""); - // Wait a bit before scanning again + // Delete the scan result to free memory for code below. + WiFi.scanDelete(); + + // Wait a bit before scanning again. delay(5000); }