#define RLED 14
#define BLED 12
#define GLED 13
/* ESP32 WiFi Scanning example */
#include "WiFi.h"
void setup() {
Serial.begin(115200); // Initialize serial communication at 115200 baud rate
Serial.println("Initializing WiFi...");
WiFi.mode(WIFI_STA); // Set WiFi to station mode
Serial.println("Setup done!");
// Set LED pins as outputs
pinMode(RLED, OUTPUT);
pinMode(BLED, OUTPUT);
pinMode(GLED, OUTPUT);
}
void loop() {
// Blink the red LED
digitalWrite(RLED, HIGH); // Turn on the red LED
delay(1000); // Wait for 1 second
digitalWrite(RLED, LOW); // Turn off the red LED
delay(1000); // Wait for 1 second
// Blink the blue LED
digitalWrite(BLED, HIGH); // Turn on the blue LED
delay(1000); // Wait for 1 second
digitalWrite(BLED, LOW); // Turn off the blue LED
delay(1000); // Wait for 1 second
// Blink the green LED
digitalWrite(GLED, HIGH); // Turn on the green LED
delay(1000); // Wait for 1 second
digitalWrite(GLED, LOW); // Turn off the green LED
delay(1000); // Wait for 1 second
Serial.println("Scanning...");
// WiFi.scanNetworks will return the number of networks found
int n = WiFi.scanNetworks();
Serial.println("Scan done!");
if (n == 0) {
Serial.println("No networks found.");
} else {
Serial.println();
Serial.print(n);
Serial.println(" networks found");
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) ? " " : "*");
delay(10);
}
}
Serial.println("");
// Wait a bit before scanning again
delay(5000);
}