Last active
June 17, 2023 20:09
-
-
Save lonelybinary/9a62052e3f9da44b3f52e54a17058e9b to your computer and use it in GitHub Desktop.
Arduino ESP32 WIFI - WIFI Scan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Arduino.h" | |
#include "WiFi.h" | |
void setup() | |
{ | |
Serial.begin(115200); | |
Serial.println("Lonely Binary Wifi Scan Demo"); | |
/* | |
Set WiFi to station mode; | |
Disconnect the previously connected WiFi; | |
Delay 100ms to ensure the WiFi disconnects; | |
*/ | |
WiFi.mode(WIFI_STA); | |
WiFi.disconnect(); | |
delay(100); | |
} | |
void loop() | |
{ | |
Serial.println("Start scanning WiFi networks"); | |
/* | |
Start Scan WiFi networks in block mode; | |
If no networks found, it will return 0; | |
If networks found, it will return the number of networks found; | |
*/ | |
int n = WiFi.scanNetworks(); | |
Serial.printf("%d network(s) found\n", n); | |
for (int i = 0; i < n; ++i) | |
{ | |
Serial.printf("(%2d) RSSI: %2d, Channel: %2d, SSID: %s \n", | |
i, WiFi.RSSI(i), WiFi.channel(i), WiFi.SSID(i)); | |
} | |
Serial.println(""); | |
// Delete the scan result to free memory for code below. | |
WiFi.scanDelete(); | |
delay(5000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment