7.2 Local Network Connectivity with Wi-Fi
Wi-Fi is a technology based on the IEEE 802.11 standards that enables wireless data exchange. The ESP32 supports common standards like 802.11b, 802.11g, and 802.11n, operating in the 2.4 GHz frequency band.
ESP32 Wi-Fi Modes
- Station Mode (STA): The ESP32 acts as a client, connecting to an existing access point (AP) like your home or university router. This is the most common mode for devices that need internet access.
- Access Point Mode (AP): The ESP32 creates its own Wi-Fi network, allowing other devices (like your phone or laptop) to connect directly to it. This is useful for initial device configuration or creating isolated local networks.
- STA + AP Mode: The ESP32 can do both simultaneously, connecting to one network while also providing its own. This allows it to act as a range extender or a bridge between networks.
Example
#include <WiFi.h>
// --- Replace with your network credentials ---
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
// -----------------------------------------
void setup() {
Serial.begin(115200); // Allow serial to initialize
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
// Start the Wi-Fi connection
WiFi.begin(ssid, password);
// Wait for the connection to complete
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected successfully!");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
}
void loop() {
// The main work is done in setup for this example.
// In a real application, you would do your networking tasks here.
delay(10000);
}
No comments to display
No comments to display