Phase 4: Connectivity 10 min read

ESP32 Wi-Fi Modes — Station, AP, and AP+STA

Understand ESP32 Wi-Fi operating modes: Station (client), Access Point (hotspot), and the dual AP+STA mode. Includes code for each mode with configuration tips.

Updated June 18, 2026

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.

ap_mode.ino
#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

ap_custom_ip.ino
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.

ap_sta_mode.ino
#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:

  1. Device boots, checks NVS flash for stored credentials
  2. If no credentials found, starts AP mode (“DeviceName-Setup”)
  3. User connects phone to the AP, opens 192.168.4.1 in browser
  4. Captive portal form collects SSID and password, stores to NVS
  5. 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_off.ino
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.

Frequently Asked Questions

WIFI_STA (Station) makes the ESP32 a client that joins an existing network. WIFI_AP (Access Point) makes the ESP32 itself a hotspot that other devices can connect to. WIFI_AP_STA enables both simultaneously.
The ESP32 AP supports a maximum of 10 simultaneous clients (stations) by default. You can adjust this with WiFi.softAP(ssid, password, channel, hidden, max_connection) where max_connection is 1–10.
No. In AP+STA mode both interfaces must use the same channel. The STA channel is determined by the router it connects to, so the AP will also use that channel.
Pass true as the fourth argument to softAP(): WiFi.softAP("MyNetwork", "password", 1, true). The network will not appear in scan results but devices that know the SSID can still connect.
By default the ESP32 AP uses DHCP and assigns addresses in the 192.168.4.x range. The ESP32 itself is at 192.168.4.1. You can change this with WiFi.softAPConfig(local_ip, gateway, subnet) before softAP().
Yes. WiFi.softAP(ssid, password) enables WPA2-PSK (AES) by default. Leave password empty ("") or omit it for an open network.
Yes. In WIFI_AP_STA mode one AsyncWebServer (or plain WebServer) instance serves requests on both interfaces using the respective IP addresses.
Call WiFi.softAPgetStationNum() for the count. For individual client MAC addresses use the esp_wifi_ap_get_sta_list() function from the esp_wifi.h SDK header.
Check that your power supply can handle the load. Also ensure WiFi.softAP() is called in setup() not loop(). Calling softAP() repeatedly re-initialises the AP and kicks all clients.
Typical indoor range is 20–50 metres. Using a whip antenna module instead of the PCB trace antenna, and keeping the line of sight clear, can extend this to 100 m outdoors.

Projects to Build

Put this knowledge to work — try one of these hands-on projects.