yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
ESP32 Core Board📖
1. ESP32 Introduction
  • 1. ESP32S3 Overview
  • 2. Environment Setup Introduction
  • 3. Dev Board Introduction
2. ESP-IDF Development Tutorial
1. Before Development
  • 1. Environment Setup (Windows)
  • 2. Environment Setup (Linux)
  • 3. Build and Flash
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. ESP_TIMER
  • 5. GPTIMER
  • 6. Watchdog Timer
  • 7. DMA
  • 8. ADC
  • 9. PWM Breathing LED
  • 10. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication Experiment
  • 2. I2C_OLED Display Experiment
  • 3. SPI Bus Communication Experiment
  • 4. PSRAM External Memory Experiment
  • 5. Flash Read and Write Experiment
  • 6. USB Emulated Mass Storage Experiment
4. FreeRTOS operating system
  • 1.FreeRTOS Core Concepts Theory
  • 2.Task Creation and Management
  • 3.Queue
  • 4.Binary Semaphore
  • 5.Mutex
  • 6.Event Groups
  • 7.Software Timer
  • 8.Task Scheduler
  • 9.Low Power Mode
  • 10.Deadlock
  • 11.Priority Inversion
5. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Client Experiment
  • 5. UDP Server Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. Socket Programming Basics
  • 9. HTTP Client Experiment
  • 10. HTTP Server Experiment
  • 11. MQTT IoT Communication Protocol
  • 12. WIFI OTA Upgrade
  • 13. Bluetooth Fundamentals
  • 14. Bluetooth Slave Mode
  • 15. Bluetooth Master Mode
6. Audio Applications
  • 1.I2S Microphone Recording and U-Disk Playback
  • 2.I2S Audio Playback Experiment
  • 3.Repeater Experiment
7. Xiaozhi AI Voice
  • 1. Burn Xiaozhi Firmware
  • 2. Network and Configuration
  • 3. AI Agent Settings
  • 4. Program Analysis
  • 5. Free Chat
3. Arduino Development Course
1. Before Development
  • 1. Environment Setup
  • 2. Build and Flash
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. ESP_TIMER
  • 5. GPTIMER
  • 6. Watchdog Timer
  • 7. ADC
  • 8. PWM Breathing LED
  • 9. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication
  • 2. I2C OLED Display
  • 3. SPI Bus Communication
  • 4. Flash Read and Write
  • 5. USB Emulated Mass Storage
4. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Server Experiment
  • 5. UDP Client Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. HTTP Client Experiment
  • 9. HTTP Server Experiment
  • 10. MQTT IoT Communication Protocol
  • 11. WIFI OTA Upgrade
  • 12. Bluetooth Fundamentals
  • 13. Bluetooth Slave Mode
  • 14. Bluetooth Master Mode
5. Audio Applications
  • 1.I2S Microphone Recording and U-Disk Playback
  • 2.I2S Audio Playback Experiment
  • 3.Repeater Experiment
4. MicroPython Development Course
1. Before Development
  • 1. Environment Setup
  • 2. Build and Flash
  • 3. Thonny IDE
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. TIMER_IT
  • 5. Watchdog Timer
  • 6. ADC
  • 7. PWM Breathing LED
  • 8. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication Experiment
  • 2. I2C_OLED Display Experiment
  • 3. SPI Bus Communication Experiment
  • 4. Flash Read and Write Experiment
  • 5. Print Storage
4. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Client Experiment
  • 5. UDP Server Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. HTTP Client Experiment
  • 9. HTTP Server Experiment
  • 10. MQTT
  • 11. Bluetooth Fundamentals
  • 12. Bluetooth Slave Mode
  • 13. Bluetooth Master Mode
5. Audio Applications
  • 1. I2S Audio Playback Experiment
  • 2. Repeater Experiment
Download
  • Code
  • Hardware_Info
  • 3D_Model_File
  • Software_Tools
  • VMware
  • VM_File
Download ZIP

Welcome to ESP32 Core Board repository

3. WIFI AP Mode

WIFI AP Mode


WIFI AP Mode1. WiFi AP Overview2. Core Concepts2.1 AP Mode Network Topology2.2 AP Configuration Parameters2.3 WPA2 Security Authentication3. Project Architecture and FlowEvent Handling Flow4. Hardware Dependencies5. Source Code Analysis5.1 Header Files and Macro Configuration5.2 wifi_event_handler() — Event Callback5.3 wifi_init_ap() — AP Initialization5.4 app_main() — Main Entry6. Operation Flow6.1 Compilation and Flashing Flow6.2 Normal Startup6.3 Device Connection and Disconnection7. Common Problems


1. WiFi AP Overview

WiFi AP (Access Point, Hotspot Mode) allows ESP32-S3 to become its own wireless router/hotspot, other devices (phones, computers, another ESP32) can search for and connect to this hotspot, enabling LAN communication.

AP mode has irreplaceable application value in IoT. First, it is the foundation of provisioning technology - when device is first deployed without available WiFi network, device runs in AP mode first, user's phone connects to hotspot then sends router password through webpage or App, device then switches to STA mode to connect (first step of SmartConfig/Web provisioning flow). Second, in scenarios without router (field operations, site inspection, temporary exhibitions), AP mode allows users to directly connect point-to-point to device for parameter configuration, status viewing and firmware upgrade, without relying on any network infrastructure. Additionally, AP mode is widely used in LAN multi-person collaboration scenarios - multiple phones or computers connect to the same ESP32-S3 hotspot for local chat, file sharing, multi-player games and other LAN applications.

ComparisonAP ModeSTA Mode
RoleHotspot (others connect to it)Client (connect to others)
IP AddressFixed 192.168.4.1DHCP dynamic assignment
DHCP ServiceESP32 provides (assigns IP to connectors)Router provides
Max ConnectionsConfigurable (default 4)N/A
Typical ScenarioProvisioning, direct control, offline LANIoT internet access, data reporting

This project implements WiFi AP mode, creating a WPA2 encrypted hotspot named ESP32_AP with password 12345678, other devices can access ESP32 via 192.168.4.1 after connecting.


2. Core Concepts

2.1 AP Mode Network Topology

           ┌──────────────────┐
           │   ESP32-S3 (AP)  │
           │   192.168.4.1    │
           │   SSID: ESP32_AP │
           └────────┬─────────┘
                    │ WiFi
        ┌───────────┼───────────┐
        │           │           │
   ┌────┴────┐ ┌────┴────┐ ┌────┴────┐
   │ Phone      │ │ PC      │ │ Another │
   │ Client1  │ │ Client2  │ │ ESP32   │
   │ .2      │ │ .3      │ │ .4      │
   └─────────┘ └─────────┘ └─────────┘

2.2 AP Configuration Parameters

xxxxxxxxxx
typedef struct {
    char     ssid[32];        // Hotspot name (max 32 bytes)
    char     password[64];    // Hotspot password (WPA2 requires ≥ 8 chars)
    uint8_t  ssid_len;        // Actual SSID length (0=auto, default)
    uint8_t  channel;         // WiFi channel (1~13, select idle channel to avoid interference)
    uint8_t  authmode;        // Encryption mode (Open/WPA/WPA2/WPA3)
    // Max simultaneous connections (default 4, max 10)
    uint8_t  max_connection;
} wifi_ap_config_t;

2.3 WPA2 Security Authentication

Auth ModeDescription
WIFI_AUTH_OPENNo password (not recommended)
WIFI_AUTH_WEPDeprecated, insecure
WIFI_AUTH_WPA2_PSKRecommended — Personal pre-shared key mode
WIFI_AUTH_WPA3_PSKMore secure, but some older devices incompatible
WIFI_AUTH_WPA2_EnterpriseEnterprise-grade

3. Project Architecture and Flow

xxxxxxxxxx
app_main()
  ├─ nvs_flash_init()                    ← Initialize NVS flash
  │
  └─ wifi_init_ap()                      ← WiFi AP initialization + start
      ├─ esp_netif_init()                → Initialize TCP/IP network stack
      ├─ esp_event_loop_create_default() → Create default event loop
      ├─ esp_netif_create_default_wifi_ap() → Create AP network interface
      ├─ esp_wifi_init()                 → Initialize WiFi driver
      ├─ Register event callbacks (WIFI_EVENT / ESP_EVENT_ANY_ID)
      ├─ Configure AP parameters (SSID/PASS/CHANNEL/MAX_CONN/AUTH)
      ├─ esp_wifi_set_mode(WIFI_MODE_AP) → Set AP mode
      ├─ esp_wifi_set_config()           → Write config
      ├─ esp_wifi_start()                → Start hotspot
      └─ Print SSID + password + IP info

Event Handling Flow

​x
WIFI_EVENT_AP_START
  → ESP_LOGI "WiFi AP started"           // Hotspot created

WIFI_EVENT_AP_STACONNECTED
  → ESP_LOGI "Station connected"         // Device connected

WIFI_EVENT_AP_STADISCONNECTED
  → ESP_LOGI "Station disconnected"      // Device disconnected

4. Hardware Dependencies

  • Hardware Connection: No external wiring, using on-board WiFi antenna

  • Dependent Components: esp_wifi, esp_netif, esp_event, nvs_flash, FreeRTOS, esp_log


5. Source Code Analysis

Complete source code: Source Code → ESP-IDF → 5.Network_Protocol → 2.WiFi_AP

5.1 Header Files and Macro Configuration

Introduce string header for calculating SSID length - AP mode must explicitly tell protocol stack the byte count of hotspot name. Remaining headers are standard combination of WiFi driver, event system, NVS flash. Macros centralize four core parameters: hotspot name, password, max connections and channel at file top for easy modification.

xxxxxxxxxx
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_log.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "nvs_flash.h"
#include "esp_netif.h"

#define TAG             "WIFI_AP"

// ==================== AP Hotspot Config ====================
#define AP_SSID         "ESP32_AP"       // Hotspot name
// Hotspot password (WPA2 ≥ 8 chars)
#define AP_PASS         "12345678"
#define AP_MAX_CONN     4                // Max connections
#define AP_CHANNEL      1                // WiFi channel

5.2 wifi_event_handler() — Event Callback

AP mode event handling is much simpler than STA mode - callback only needs to manage three cases: hotspot created, device connected, device disconnected. AP doesn't need to get dynamic IP from router like STA - AP's own IP is fixed at 192.168.4.1, therefore no need to register IP event callback. Each event just logs it, upper layer HTTP/TCP service depends on these events to determine device connection status.

xxxxxxxxxx
static void wifi_event_handler(void* arg, esp_event_base_t event_base,
                               int32_t event_id, void* event_data)
{
    // Hotspot created successfully
    if (event_id == WIFI_EVENT_AP_START)
    {
        ESP_LOGI(TAG, "WiFi AP started");
    }
    // Device disconnected
    else if (event_id == WIFI_EVENT_AP_STADISCONNECTED)
    {
        ESP_LOGI(TAG, "Station disconnected");
    }
    // Device connected
    else if (event_id == WIFI_EVENT_AP_STACONNECTED)
    {
        ESP_LOGI(TAG, "Station connected");
    }
}

5.3 wifi_init_ap() — AP Initialization

WiFi AP initialization flow is the same as STA - network stack initialization, event loop creation, network interface creation, WiFi driver initialization, fixed order. But there are three key differences:

  • Network interface uses AP version creation function, not STA version, this determines ESP32 runs as hotspot not client.

  • Event callback only registers WiFi events, no IP events - AP's IP is fixed at 192.168.4.1, doesn't depend on DHCP assignment.

  • Configuration struct fills AP members. SSID length field must explicitly tell protocol stack the byte count of the string, different from STA mode where system calculates automatically.

Note that there's no need to call connection function - hotspot takes effect automatically after starting, just wait for other devices to connect.

xxxxxxxxxx
void wifi_init_ap(void)
{
    esp_netif_init();
    esp_event_loop_create_default();
    esp_netif_create_default_wifi_ap();

    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    esp_wifi_init(&cfg);

    // Register WiFi event callback
    esp_event_handler_instance_register(WIFI_EVENT,
                                        ESP_EVENT_ANY_ID,
                                        &wifi_event_handler,
                                        NULL,
                                        NULL);

    wifi_config_t wifi_config = {
        .ap = {
            .ssid = AP_SSID,                        // Hotspot name
            .password = AP_PASS,                    // Password
            .ssid_len = strlen(AP_SSID),
            .channel = AP_CHANNEL,                  // Channel
            // Max connections
            .max_connection = AP_MAX_CONN,
            .authmode = WIFI_AUTH_WPA2_PSK
        }
    };

    // Set hotspot mode
    esp_wifi_set_mode(WIFI_MODE_AP);
    esp_wifi_set_config(WIFI_IF_AP, &wifi_config);  // Apply config
    esp_wifi_start();                               // Start hotspot
    // Log SSID and password
    ESP_LOGI(TAG, "SSID: %s, PASS: %s", AP_SSID, AP_PASS);             
    ESP_LOGI(TAG, "ESP32 IP: 192.168.4.1");         // AP fixed IP
}

5.4 app_main() — Main Entry

Main entry function does two things - first initialize NVS flash (required prerequisite for WiFi driver), then call initialization function to start hotspot. Final infinite loop ensures program doesn't exit, actual hotspot management and device connection are all handled asynchronously in event callback.

xxxxxxxxxx
void app_main(void)
{
    nvs_flash_init();                    // Initialize NVS flash
    wifi_init_ap();                      // Start AP mode

    while (1)
    {
        // Keep program running
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
}

6. Operation Flow

6.1 Compilation and Flashing Flow

ESP-IDF flashing flow: See ESP-IDF → 1. Before Development → 3. Build and Flash.

6.2 Normal Startup

After flashing, reset development board, serial assistant will output the following - SSID/PASS confirms hotspot started, DHCP server started means DHCP server ready to assign IPs to clients, WiFi AP started is user log from event callback, last line emphasizes AP fixed IP:

Log field meanings:

FieldExampleMeaning
IIINFO level log
WIFI_APWIFI_APLog tag
esp_netif_lwipesp_netif_lwipNetwork interface DHCP service log
SSID:ESP32_APHotspot name
PASS:12345678Hotspot password
DHCP server startedDHCP server startedDHCP server started, begins assigning IP to connected devices
WiFi AP startedWiFi AP startedWiFi AP hotspot successfully created
ESP32 IP:192.168.4.1AP fixed IP address
xxxxxxxxxx
I (551) WIFI_AP: SSID: ESP32_AP, PASS: 12345678
I (551) esp_netif_lwip: DHCP server started on interface WIFI_AP_DEF with IP: 192.168.4.1
I (571) WIFI_AP: WiFi AP started
I (571) WIFI_AP: ESP32 IP: 192.168.4.1

Hotspot Ready

6.3 Device Connection and Disconnection

Search WiFi with phone, find ESP32_AP, enter password 12345678 to connect. Connection process outputs in order - Station connected is association success log from user code callback, then wifi:new:<1,1> indicates driver internal state changed from "no associated devices" to "1 associated device", two wifi:<ba-add> are link layer Block Ack negotiation complete, finally DHCP server assigned IP means DHCP has assigned IP to client, at which point device can communicate normally:

Log field meanings:

FieldExampleMeaning
Station connectedStation connectedDevice associated to hotspot (user code event callback output)
wifi:new:<1,1>new:<1,1>WiFi driver state transition: associated devices count from 0 to 1 (IDF underlying log)
wifi:<ba-add>ba-addWiFi driver Block Ack negotiation successful, link layer ready (IDF underlying log)
DHCP server assigned IP192.168.4.2DHCP server assigned IP address to client, device can communicate normally
xxxxxxxxxx
I (11061) WIFI_AP: Station connected
I (11091) wifi:new:<1,1>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (11111) wifi:<ba-add>idx:2 (ifx:1, e6:d1:24:85:df:49), tid:0, ssn:0, winSize:64
I (11121) wifi:<ba-add>idx:3 (ifx:1, e6:d1:24:85:df:49), tid:7, ssn:0, winSize:64
I (11151) esp_netif_lwip: DHCP server assigned IP to a client, IP is: 192.168.4.2

Connection Success

After disconnection, log shows complete link teardown process - three wifi:<ba-del> are driver deleting Block Ack sessions one by one, releasing link layer resources, wifi:new:<1,0> indicates driver internal state from "1 associated device" to "0 devices", finally Station disconnected is user code event callback confirming disconnect:

FieldExampleMeaning
wifi:<ba-del>ba-delWiFi driver deleted Block Ack session, link layer released resources (IDF underlying log)
wifi:new:<1,0>new:<1,0>WiFi driver state transition: associated devices from 1 to 0 (IDF underlying log)
Station disconnectedStation disconnectedClient disconnected from hotspot (user code event callback output)
xxxxxxxxxx
I (256871) wifi:<ba-del>idx:2, tid:0
I (256871) wifi:<ba-del>idx:4, tid:5
I (256871) wifi:new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1, snd_ch_cfg:0x0
I (256881) wifi:<ba-del>idx:3, tid:7
I (256891) WIFI_AP: Station disconnected

Disconnect


7. Common Problems

SymptomCauseSolution
Phone can't find hotspotWiFi not started normally / channel occupiedCheck serial logs confirm WiFi AP started; try changing AP_CHANNEL (e.g., 6, 11)
"Password incorrect" when connectingPassword less than 8 chars or SSID abnormalWPA2 requires password ≥ 8 chars; confirm AP_PASS length is sufficient
Can't access 192.168.4.1 after connectingNo HTTP/TCP server runningAP is just network layer, need upper layer service listening on port to respond
New device can't connect after multiple devices connectedAP_MAX_CONN too smallIncrease AP_MAX_CONN (max 10), but note memory consumption
Hotspot unstable, frequent disconnections2.4G channel interferenceUse WiFi channel scan tool to select idle channel, modify AP_CHANNEL
WIFI_EVENT_AP_START no logNVS not initializedEnsure nvs_flash_init() called at beginning of app_main()
WIFI STA Mode
UDP Client Experiment

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文