The Three Wi-Fi Modes
Every ESP32 Wi-Fi session begins by choosing one of three operating modes. The mode tells the radio whether it should act as a client joining someone else’s network, a host creating its own network, or both at once.
| Mode Constant | Role | Typical Use Case |
|---|---|---|
WIFI_STA |
Station (client) | Joining your home/office network |
WIFI_AP |
Access Point (hotspot) | Provisioning, local control without internet |
WIFI_AP_STA |
Both simultaneously | OTA updates, bridging, captive portal |
WIFI_OFF |
Radio disabled | Ultra-low power deep sleep |
Station Mode (WIFI_STA)
Station mode is the most common. The ESP32 connects to an existing router and receives an IP address via DHCP. This is what the Wi-Fi Basics guide demonstrates. The key call is WiFi.mode(WIFI_STA) followed by WiFi.begin(ssid, password).
Access Point Mode (WIFI_AP)
In AP mode the ESP32 becomes a Wi-Fi hotspot. Phones, laptops, or other ESP32 boards can connect directly to it — no external router required. This is ideal for local control panels, field devices with no existing infrastructure, and the Wi-Fi provisioning workflow.
#include <WiFi.h>
const char* ap_ssid = "ESP32-Config";
const char* ap_password = "12345678"; // min 8 chars, or "" for open
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_AP);
bool ok = WiFi.softAP(ap_ssid, ap_password);
if (ok) {
Serial.println("AP started");
Serial.print("AP IP: ");
Serial.println(WiFi.softAPIP()); // default: 192.168.4.1
} else {
Serial.println("AP failed — check credentials");
}
}
void loop() {
Serial.printf("Clients connected: %d\n", WiFi.softAPgetStationNum());
delay(5000);
}
Customising the AP Address
IPAddress ap_ip(10, 0, 0, 1);
IPAddress ap_gw(10, 0, 0, 1);
IPAddress ap_sub(255, 255, 255, 0);
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(ap_ip, ap_gw, ap_sub);
WiFi.softAP("MyESP32", "password123");
Serial.println("AP IP: " + WiFi.softAPIP().toString()); // 10.0.0.1
AP + STA Dual Mode (WIFI_AP_STA)
Dual mode lets the ESP32 stay connected to your home router as a client while simultaneously acting as its own hotspot. This is essential for OTA updates (download from the internet, serve the hotspot UI locally) and for bridging sensors that can only reach the ESP32 AP with a cloud backend reached via the STA interface.
#include <WiFi.h>
const char* sta_ssid = "HomeRouter";
const char* sta_pass = "routerPassword";
const char* ap_ssid = "ESP32-Local";
const char* ap_pass = "esp32pass";
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_AP_STA);
// Start STA connection
WiFi.begin(sta_ssid, sta_pass);
// Start AP (runs immediately; STA connects in background)
WiFi.softAP(ap_ssid, ap_pass);
Serial.println("AP IP: " + WiFi.softAPIP().toString());
// Wait for STA to connect
while (WiFi.status() != WL_CONNECTED) {
delay(500); Serial.print(".");
}
Serial.println("\nSTA IP: " + WiFi.localIP().toString());
}
void loop() {
if (WiFi.status() != WL_CONNECTED) {
WiFi.reconnect();
delay(5000);
}
}
Channel Constraint in Dual Mode
A subtle but important limitation: in AP+STA mode both interfaces share the same radio and therefore must operate on the same Wi-Fi channel. The channel is set by the router the STA connects to. If your router uses channel 11, the ESP32 AP will also use channel 11 — you cannot override this.
Wi-Fi Provisioning with AP Mode
A common pattern for shipping consumer devices:
- Device boots, checks NVS flash for stored credentials
- If no credentials found, starts AP mode (“DeviceName-Setup”)
- User connects phone to the AP, opens 192.168.4.1 in browser
- Captive portal form collects SSID and password, stores to NVS
- Device reboots, now connects to home router in STA mode
Turning Wi-Fi Off Completely
For battery-powered sensors that send data periodically, turn off the radio between transmissions:
WiFi.disconnect(true); // disconnect and clear credentials WiFi.mode(WIFI_OFF); // power down the radio esp_wifi_stop(); // full RF power cut (saves ~20 mA)
Re-enable with esp_wifi_start() and WiFi.begin(ssid, pass) when you need to send the next reading.