Join Wi-Fi

Wi-Fi SoftAP hotspot

The device hosts its own hotspot for phone-based provisioning or local control.

Join Wi-Fi Device hotspot ESP32 Wi-Fi parts

Official path: examples/wifi/getting_started/softAP

01 Overview

The ESP32 operates as a SoftAP, broadcasting an SSID and allowing stations to connect. This is a common approach for first-time setup or environments without a router.

Use it for out-of-box setup, factory floor LAN, or device debugging. A phone or laptop can connect directly to the hotspot and access services hosted on the device.

Avoid it when the device is already on the customer's router and only needs cloud access. SoftAP consumes Wi-Fi resources and an open hotspot is a security risk.

The official example verifies SSID broadcast, STA association, and DHCP IP assignment. It does not implement a captive portal, auto-shutdown, or AP+STA coexistence policy.

For production, you must implement a configuration page, password authentication, and timeout shutdown yourself.

02 Hardware

  • Module and antenna: Same as Station mode; use onboard or external antenna, ensure antenna keep-out area.
  • Power: Multiple connected clients increase current draw and heat; ensure adequate 3.3V rail margin, use LDO or DC-DC with decoupling capacitors.
  • Status LED: Connect an LED to indicate hotspot status for user feedback.
  • Button: A button can trigger SoftAP mode for factory reset or provisioning.
  • Interfaces: For local control, provide UART, I2C, or GPIO interfaces as needed.
  • Layout: Keep antenna away from metal and high-speed signal lines to avoid interference.

03 Software flow

1. Initialize NVS and Wi-Fi, call esp_netif_init() and esp_event_loop_create_default().

2. Create an AP network interface and configure esp_netif for AP mode.

3. Set WIFI_MODE_AP with SSID, password, channel, and max client count.

4. Start Wi-Fi and wait for system events; the DHCP server automatically assigns IPs to stations.

5. Start an HTTP server to serve a configuration page or local control interface.

6. Handle client connection events and track connection status.

7. After provisioning, switch to STA or APSTA mode based on user input, and shut down the hotspot.

8. Implement a timeout shutdown, e.g., auto-off after 10 minutes with no clients.

04 Core points

  • An open hotspot is a security risk. At minimum, require a password and a timeout.
  • Choose a channel with minimal interference. Scan channels and select a free one.
  • Customization options: captive portal, AP+STA mode, hotspot shutdown policy.
  • Note: When SoftAP coexists with STA, allocate channel and power carefully to avoid performance degradation.
  • Do not copy SoftAP code from other chips directly; adjust to ESP-IDF APIs.
  • Customize SSID and password for your product, avoid defaults.

中文

连上 Wi-Fi

Wi-Fi SoftAP 热点

设备自建热点,手机连接后用于配网或本地控制。

连上 Wi-Fi 设备开热点 ESP32 Wi-Fi parts

官方路径: examples/wifi/getting_started/softAP

01 项目概述

ESP32 作为 SoftAP 运行,广播 SSID 并允许 STA 连接。这是首次配网或现场无路由器场景的常用方案。

适用场景:开箱即连、产线局域网、设备调试。手机或电脑直接连接热点即可访问设备提供的服务。

不适用场景:设备已接入客户路由器,仅需上云。此时 SoftAP 会占用 Wi-Fi 资源,且开放热点有安全风险。

官方示例已验证:广播 SSID、STA 关联、DHCP 分配 IP。但未实现配网门户、超时自动关闭、AP+STA 共存策略。

产品化时需自行实现配网页面、密码认证、超时关闭等逻辑。

02 项目硬件描述

  • 模组与天线: 与 Station 模式相同,使用板载天线或外接天线,注意天线净空区。
  • 电源: 多客户端连接时电流和发热增加,需预留 3.3V 电源余量,建议使用 LDO 或 DC-DC 并加去耦电容。
  • 指示灯: 可连接 LED 指示热点状态,便于用户判断。
  • 按键: 可配置按键触发 SoftAP 模式,用于恢复出厂或进入配网。
  • 接口: 如需本地控制,可提供 UART、I2C 或 GPIO 接口。
  • 布局: 天线远离金属和高速信号线,避免干扰。

03 项目软件流程描述

1. 初始化 NVS 和 Wi-Fi,调用 esp_netif_init() 和 esp_event_loop_create_default()。

2. 创建 AP 网络接口,配置 esp_netif 为 AP 模式。

3. 设置 WIFI_MODE_AP,配置 SSID、密码、信道、最大连接数。

4. 启动 Wi-Fi,等待系统事件,DHCP 服务器自动为 STA 分配 IP。

5. 启动 HTTP 服务器,提供配网页面或本地控制接口。

6. 处理客户端连接事件,记录连接状态。

7. 配网完成后,根据用户输入切换至 STA 或 APSTA 模式,并关闭热点。

8. 实现超时关闭逻辑,例如 10 分钟无客户端连接则自动关闭热点。

04 项目核心点

  • 开放热点存在安全风险。 至少需设置密码和超时关闭。
  • 选择干扰较小的信道。 可扫描周围信道并选择空闲信道。
  • 可定制项: 配网门户、AP+STA 模式、热点关闭策略。
  • 注意: SoftAP 与 STA 共存时,需合理分配信道和功率,避免性能下降。
  • 不要直接复制其他芯片的 SoftAP 代码, 需根据 ESP-IDF API 调整。
  • 产品需自定义 SSID 和密码, 避免使用默认值。