Join Wi-Fi

Wi-Fi Station join

Join an existing router and get an IP. Almost every cloud product starts here.

Join Wi-Fi Join a router ESP32 / S2 / S3 / C3 / C6 (Wi-Fi parts)

Official path: examples/wifi/getting_started/station

01 Overview

The chip runs as STA and joins an AP. This sits under almost every ESP32 cloud product.

Use when: the site already has Wi-Fi, and the device needs internet or LAN access.

Skip when: no router (SoftAP / provisioning) or phone-only control (BLE).

Official proves: SSID/password, printed IP, retries then fail log.

Official does not: provisioning UI, encrypted storage, antenna certification.

Real products need to add provisioning, reconnection, and secure storage on top.

02 Hardware

  • Chip: Wi-Fi ESP32 parts (ESP32, S2, S3, C3, C6). H2 has no Wi-Fi.
  • Minimum parts: module (with antenna), 3.3V supply, reset circuit. Antenna on the module.
  • Layout: keep-out under antenna; metal housings need a window.
  • Power: TX current spikes; add decoupling caps to avoid resets.
  • Power supply: use a low-dropout regulator for stable 3.3V.
  • Connectors: if external antenna, use IPEX with impedance matching.
  • Other: add LED for Wi-Fi status indication for debugging.

03 Software flow

1. Init NVS (required by Wi-Fi driver).

2. Register STA events including GOT_IP and disconnect.

3. Load SSID/password from menuconfig, start WIFI_MODE_STA.

4. State machine: init → auth → assoc → run.

5. Products wait for GOT_IP before MQTT/HTTP; never ship hardcoded credentials.

6. Implement reconnection strategy with backoff after disconnection.

7. Use event loop to handle post-IP business logic.

04 Core points

  • Hardcoded passwords cannot ship.
  • Associated is not “cloud ready”.
  • Retry policy is a battery decision.
  • Custom work: provisioning, reconnect policy, antenna layout, cloud stack.
  • Be aware of Wi-Fi behavior differences across chips; test accordingly.

中文

连上 Wi-Fi

Wi-Fi Station 入网

设备加入现有路由器并拿到 IP。上网产品几乎都从这里开始。

连上 Wi-Fi 加入路由器 ESP32 / S2 / S3 / C3 / C6 (Wi-Fi parts)

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

01 项目概述

设备作为 STA 连接 AP。几乎所有要上云的 ESP32 产品都经过这一步。

适用:现场已有 Wi-Fi,设备需要访问互联网或局域网服务。

不适用:没有路由器(看 SoftAP/配网);只要近场手机控制(看 BLE)。

官方能证明:填 SSID/密码,成功打印 IP;失败重试后报错。

官方没做的:配网界面、密码加密存放、天线认证。

实际产品需要在此之上叠加配网、重连、安全存储等机制。

02 项目硬件描述

  • 芯片: 带 Wi-Fi 的 ESP32 系列(如 ESP32、S2、S3、C3、C6)。H2 无 Wi-Fi。
  • 最小物料: 模组(含天线)、3.3V 电源、复位电路。天线在模组上。
  • 布局: 天线下方净空,金属壳需开窗,避免遮挡。
  • 供电: 发射瞬间电流冲高,需加去耦电容,否则可能掉线或复位。
  • 电源: 建议使用低 dropout 稳压器,确保 3.3V 稳定。
  • 连接器: 如需外接天线,选用 IPEX 连接器,注意阻抗匹配。
  • 其他: 可加 LED 指示 Wi-Fi 状态,便于调试。

03 项目软件流程描述

1. 初始化 NVS(Wi-Fi 驱动依赖)。

2. 注册 STA 事件:开始连接、GOT_IP、断开。

3. menuconfig 写入 SSID/密码,启动 WIFI_MODE_STA。

4. 状态:init → auth → assoc → run。

5. 产品必须等 GOT_IP 再开 MQTT/HTTP;SSID 不能写死出货。

6. 断线后需实现重连策略,如指数退避。

7. 可添加事件循环处理 IP 获取后的业务逻辑。

04 项目核心点

  • 写死密码不能出货。 要配网 + NVS + 重置键。
  • 连上 ≠ 业务可用。 先 IP,后云。
  • 重试策略影响电池。 官方重试只是演示。
  • 可定制: 配网、断线策略、天线布局、与云协议拼接。
  • 注意不同芯片的 Wi-Fi 行为差异,需针对性测试。