Join Wi-Fi

Wi-Fi Power Save

Stay associated with less current. Required reading for battery products after Station.

Join Wi-Fi Wi-Fi power saveJoin a router ESP32 Wi-Fi parts

Official path: examples/wifi/power_save

01 Overview

This example demonstrates power save modes (such as MIN_MODEM) for ESP32 in Station mode, focusing on reducing average current while keeping the Wi-Fi connection alive.

It solves the problem of battery-powered IoT devices that need to stay online but cannot afford high Wi-Fi power consumption. Proper configuration of power save modes significantly reduces average current without disconnecting.

Use this when: periodic telemetry (e.g., temperature, humidity, battery level), latency-tolerant reporting, or maintaining sparse TCP/UDP connections.

Skip this when: you need millisecond downlink (e.g., remote control, real-time audio/video) or high throughput (e.g., OTA).

Note: Power save is not deep sleep; the device remains associated and consumes milliamps, far more than deep sleep.

This is an official ESP-IDF example showing how to configure and measure power saving, providing a reference for real products.

02 Hardware

  • Power integrity: Power supply ripple and transient response matter more than the mode enum. Ripple or voltage drops cause RF reconnect storms, increasing power consumption.
  • Battery path: The battery path must have low impedance and survive TX pulses (hundreds of mA). Otherwise, voltage drops may cause brownouts or reconnects.
  • Decoupling capacitors: Place sufficient decoupling (e.g., 10uF + 100nF) near the ESP32 power pins, and keep the antenna area clean.
  • Antenna matching: Poor antenna matching increases TX power consumption, especially in power save modes. Ensure proper impedance matching.
  • Peripheral leakage: Sensors, LEDs, and other peripherals should have low quiescent current; otherwise, they will negate the power saving benefits.
  • Measurement point: Include a current sense resistor or jumper to measure current in different modes.
  • Layout: Avoid long, thin power traces to reduce parasitic inductance.

03 Software flow

1. First connect as a Station to the AP and ensure network connectivity.

2. Call esp_wifi_set_ps(WIFI_PS_MIN_MODEM) to set the power save mode (or WIFI_PS_NONE to disable).

3. Configure the listen interval (e.g., via esp_wifi_set_config with listen_interval) related to DTIM.

4. Run the main loop: periodically report data while keeping the connection.

5. Use the ESP-IDF power save example code and observe logs and power consumption.

6. Measure average current and packet loss for different power save modes and record the data.

7. Adjust the report period and listen interval based on product requirements to find the balance between power and latency.

8. Note: In power save mode, Wi-Fi may delay data reception; handle timeouts and retransmissions at the application layer.

04 Core points

  • This is not deep sleep: The device remains associated and consumes milliamps, not microamps.
  • AP DTIM dominates sleep depth: Longer DTIM intervals allow deeper sleep but increase downlink latency. Lab APs may have different DTIM settings than field APs, making lab data misleading.
  • Measure realistically: Use a battery or adjustable power supply and measure average current, not peak. Account for TX pulses.
  • Custom work: Adjust report period, listen interval, and power save level (e.g., WIFI_PS_MAX_MODEM) based on your product's current budget and latency requirements.
  • Don't copy across chips: Different ESP32 variants (e.g., ESP32-S3, C3) have different power characteristics; re-measure for each.
  • AP compatibility: Some APs may not support long DTIM intervals; test compatibility with target APs.

中文

连上 Wi-Fi

Wi-Fi Power Save 省电

连着路由器时如何少耗电。电池产品在 Station 之后必读。

连上 Wi-Fi Wi-Fi 省电加入路由器 ESP32 Wi-Fi parts

官方路径: examples/wifi/power_save

01 项目概述

本示例演示 ESP32 在保持 Wi-Fi 连接(Station 模式)下的省电模式,重点介绍 MIN_MODEM 等 modem sleep 模式。

解决的问题:电池供电的物联网设备需要长期在线,但 Wi-Fi 射频是耗电大户。通过合理配置省电模式,可以在不中断连接的前提下显著降低平均电流。

适用场景:周期上报传感器数据(如温湿度、电量)、可接受秒级延迟的遥测、需要保持 TCP/UDP 连接但流量稀疏的设备。

不适用场景:需要毫秒级下行响应(如遥控、实时音视频)、高吞吐量传输(如 OTA 大文件)。

注意:省电模式不是深睡,设备仍保持关联,功耗远高于 deep sleep。

本示例是 ESP-IDF 官方示例,展示了如何配置和测量省电效果,为实际产品提供参考。

02 项目硬件描述

  • 电源完整性: 电源纹波和瞬态响应比省电模式选择更重要。纹波大或电源跌落会导致射频反复重连,反而更耗电。
  • 电池路径: 电池供电时,路径阻抗要低,能承受 TX 脉冲(数百 mA 级),否则电压跌落会触发欠压复位或重连。
  • 去耦电容: 在 ESP32 电源引脚附近放置足够容量的去耦电容(如 10uF + 100nF),并靠近天线区域保持干净。
  • 天线匹配: 天线匹配不良会增加发射功耗,省电模式下尤其明显。确保天线阻抗匹配。
  • 外部器件: 传感器、LED 等外设的静态电流要低,否则会淹没 Wi-Fi 省电的收益。
  • 测量点: 预留电流测量跳线或采样电阻,方便实测不同模式下的电流。
  • 布局注意: 避免电源线过长、过细,减少寄生电感。

03 项目软件流程描述

1. 先以 STA 模式连接 AP,确保网络正常。

2. 调用 esp_wifi_set_ps(WIFI_PS_MIN_MODEM) 设置省电模式(或 WIFI_PS_NONE 关闭)。

3. 配置 DTIM 间隔相关的监听间隔(如 esp_wifi_set_inactive_time 或通过 esp_wifi_set_config 设置 listen_interval)。

4. 运行主循环:周期上报数据,期间保持连接。

5. 使用 ESP-IDF 的 power save 示例代码,观察日志输出和功耗。

6. 测量不同省电模式下的平均电流和丢包率,记录数据。

7. 根据产品需求调整上报周期和监听间隔,找到功耗与延迟的平衡点。

8. 注意:在省电模式下,Wi-Fi 可能延迟接收数据,需在应用层处理超时重传。

04 项目核心点

  • 省电不是深睡: 设备仍维持关联,功耗在 mA 级,远高于 deep sleep 的 uA 级。
  • 路由器 DTIM 决定睡眠深度: DTIM 间隔越长,设备可睡眠越久,但下行延迟越大。实验室 AP 的 DTIM 可能与现场不同,导致实测数据失真。
  • 测量要真实: 使用电池或可调电源,测量平均电流而非峰值。注意 TX 脉冲。
  • 可定制: 根据产品需求调整上报周期、监听间隔、省电档位(如 WIFI_PS_MAX_MODEM)。
  • 不要照搬: 不同 ESP32 芯片(如 ESP32-S3、C3)的功耗特性不同,需重新测量。
  • 注意兼容性: 某些 AP 可能不支持长 DTIM,需测试兼容性。