#include <WiFi.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
printMsg("Hello, ESP32!");
WiFi.mode(WIFI_STA);
WiFi.disconnect();
}
void loop() {
int n = WiFi.scanNetworks();
if (n == 0) {
printMsg("No networks found");
return;
}
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(")");
printMsg((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
}
delay(10); // this speeds up the simulation
connect();
}
void connect() {
WiFi.begin("Wokwi-GUEST", "", 6); // Specify WiFi channel number (6) for faster connection
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
printMsg(" Connected!");
printMsg("WiFi status code: " + WiFi.status());
printMsg("Local IP: " + WiFi.localIP());
}
void printMsg(String msg) {
Serial.println(msg);
delay(100);
}