#include <WiFi.h> // Include the WiFi library
// Replace with your network credentials (STATION)
#define ssid "Wokwi-GUEST"
#define password ""
// Function to initialize WiFi connection
void initWiFi() {
WiFi.mode(WIFI_STA); // Set WiFi mode to station (client)
WiFi.begin(ssid, password); // Begin WiFi connection with provided credentials
// Display connection status while attempting to connect
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.println(WiFi.status());
Serial.print('.'); // Print dots to indicate connection progress
delay(1000); // Wait for 1 second before checking connection status again
}
// If connected, print connection details
Serial.println("Connected");
Serial.println(WiFi.status()); // Print WiFi connection status
Serial.println(WiFi.localIP()); // Print local IP address obtained from DHCP
Serial.print("RRSI: ");
Serial.println(WiFi.RSSI()); // Print WiFi signal strength (RSSI)
}
void setup() {
Serial.begin(115200); // Initialize serial communication at 115200 baud rate
initWiFi(); // Call the function to initialize WiFi connection
}
void loop() {
// put your main code here, to run repeatedly:
}