Wi-Fi Low Power Mode

Last Updated on : 2025-07-01 02:13:41download

Overview

Concepts

Wi-Fi low power modes can be categorized into the following types based on their implementation principles and power consumption levels:

  • Standard low power
  • Power-off
  • Deep sleep
  • Access point (AP) persistent keep-alive

The following table lists the main features of each mode.

Low power mode Features
Standard low power Keep a persistent Wi-Fi connection, enable rapid data reporting, and operate at < 15 mA power consumption.
Power-off The Wi-Fi connection is disconnected. The module powers down and requires a restart when needed (typically coordinated with an MCU), resulting in slower data reporting speeds.
Deep sleep The Wi-Fi connection is disconnected. The module can be awakened via GPIO, timer, or other methods when proactive reporting is required (system reboots after wakeup), resulting in slower data reporting speeds and μA-level power consumption.
AP persistent keep-alive A persistent Wi-Fi connection is maintained. When proactive reporting is required, the module can be awakened via GPIO interrupts or other methods without requiring a system reboot. This delivers faster data reporting speeds while maintaining power consumption at hundreds of microamps (μA).

How it works

  • The Wi-Fi device enters low power mode by putting both the CPU and RF into sleep states, waking on demand to achieve power savings.
  • When the RF enters sleep mode, the device negotiates scheduled wakeups with the router for data processing. The router buffers data during the device’s sleep periods, and the device returns to sleep after completing data transactions. For more information, see DTIM.
  • When the CPU is in sleep mode, it immediately wakes upon demand. For more information, see tickless mode.

API description

TuyaOS provides a variety of APIs to implement various low power modes. For specific usage, refer to the examples.

Set low power mode of the CPU

Set whether the CPU supports low power mode. The low power mode must be enabled before managing CPU power state transitions.

/**
 * @brief Set CPU low power mode
 *
 * @param[in] lp_enable
 *
 * @return none
 */
VOID_T tal_cpu_set_lp_mode(BOOL_T lp_enable);

Enable low power mode of the CPU

Control the CPU to enter tickless low power mode. You need to set the CPU low power mode tal_cpu_set_lp_mode(TRUE).

/**
 * @brief Enable CPU low power mode
 *
 * @param[in] param: none
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tal_cpu_lp_enable(VOID_T);

Disable low power mode of the CPU

Control the CPU to exit the low power mode. This API must be used in conjunction with tal_cpu_lp_enable to prevent power management instability.

/**
 * @brief Disable CPU low power mode
 *
 * @param[in] param: none
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tal_cpu_lp_disable(VOID_T);

Enable low power Wi-Fi

Control the Wi-Fi module to enter low power mode (DTIM-1 by default). The CPU low power mode will be set synchronously by default.

/**
 * @brief Enable Wi-Fi low power mode (together with CPU).
 *
 * @param[in] none
 * @return  OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tal_wifi_lp_enable(VOID_T);

Disable low power Wi-Fi

Control the Wi-Fi module to exit low power mode.

  • By default, the CPU will exit low power mode synchronously.
  • This API must be used in conjunction with tal_wifi_lp_enable to prevent power management instability.
/**
 * @brief Disable Wi-Fi low power mode (together with CPU).
 *
 * @param[in] none
 * @return  OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tal_wifi_lp_disable(VOID_T);

Enable low power Wi-Fi only

Control only the Wi-Fi module to enter low power mode (DTIM-1 by default).

/**
 * @brief Enable Wi-Fi low power mode only
 *
 * @param[in]       none
 * @return  OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tal_wifi_lp_enable_v2(VOID_T);

Disable low power Wi-Fi only

Control the Wi-Fi module to exit the low power mode. This API must be used in conjunction with tal_wifi_lp_enable_v2 to prevent power management instability.

/**
 * @brief Disable Wi-Fi low power mode only
 *
 * @param[in]       none
 * @return  OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tal_wifi_lp_disable_v2(VOID_T);

Enable ultra-low power Wi-Fi (AP persistent keep-alive)

Control the Wi-Fi module to enter adaptive ultra-low power mode ( DTIM-10 by default). In this mode, the CPU also synchronously enters ultra-low power mode (tickless), with a maximum sleep duration of 5 seconds (without interrupt wakeup and data interaction wakeup).

/**
 * @brief Enable ultra low power mode
 *
 * @param[in] none
 *
 * @return  OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tuya_wifi_ulp_init(VOID);

/**
 * @brief register CPU or wifi power mode for feature(HTTP_CONN, OTA, MQTT_CONN, UART, U2C, SPI, PWM, KEY)
 *
 * @param[in] type    function module
 * @retval 0          success
 * @retval Other      fail
 */
int lpmgr_register(TY_LP_TYPE type);

/**
 * @brief unregister CPU or wifi power mode for feature(HTTP_CONN, OTA, MQTT_CONN, UART, U2C, SPI, PWM, KEY)
 *
 * @param[in] type    function module
 * @retval 0          success
 * @retval Other      fail
 */
int lpmgr_unregister(TY_LP_TYPE type);

Set the wakeup source for exiting low power mode

Set the wakeup source for the device to exit low power mode.

You need to configure the wakeup source only for deep sleep mode and AP persistent keep-alive mode.

/**
 * @brief Set the wake-up source
 *
 * @param[in] param: Set the wake-up source,
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

OPERATE_RET tkl_wakeup_source_set(CONST TUYA_WAKEUP_SOURCE_BASE_CFG_T  *param);

Example

Standard low power

void test_lowpower(void)
{
    // 1. Call the API as early as possible, such as tuya_app_main() function.
    tal_cpu_set_lp_mode(TRUE);

    // 2. Call this API when the Wi-Fi module is connected to the router.
    tal_wifi_lp_enable();

    // 3. Call this API when the Wi-Fi module is disconnected from the router.
    tal_wifi_lp_disable();

    // 4. In other scenarios, such as when you need to receive Wi-Fi management frames, you must exit Wi-Fi low power mode first, and then turn it on after receiving the frames.
}

Deep sleep

void test_lowpower(void)
{
    // 1. Set the wakeup source (GPIO)
    TUYA_WAKEUP_SOURCE_BASE_CFG_T wakeup_cfg;
    wakeup_cfg.source = TUYA_WAKEUP_SOURCE_GPIO;
    wakeup_cfg.wakeup_para.gpio_param.gpio_num = TUYA_GPIO_NUM_28; // Configure based on the actual product.
    wakeup_cfg.wakeup_para.gpio_param.level = TUYA_GPIO_WAKEUP_RISE; // Configure based on the actual product.
    tkl_wakeup_source_set(&wakeup_cfg);

    // 2. Turn off non-essential peripherals, otherwise it might affect the actual power consumption.
    // xxx

    // 3. Enter the deep sleep mode.
    tal_cpu_sleep_mode_set(TRUE, TUYA_CPU_DEEP_SLEEP);
}

AP persistent keep-alive

void test_lowpower(void)
{
    // 1. Call the API as early as possible, such as tuya_app_main() function.
    tuya_wifi_ulp_init();

    // 2. Call this API when you want to exit ultra-low power mode.
    lpmgr_register(TY_LP_UART); // Configure based on the actual product.

    // 3. Call this API when you want to enter ultra-low power mode.
    lpmgr_unregister(TY_LP_UART); // Configure based on the actual product.
}

Things to note

Low power APIs must be used in matched pairs. Otherwise, power consumption anomalies might occur, failing to achieve the expected low power performance.

FAQs

How to select low power mode?

The Wi-Fi module typically operates at tens of milliamps during active states (exact values vary by module, with peak currents being slightly higher). The essence of low power modes is to reduce this baseline power consumption. For power-insensitive products (such as mains-powered devices), you can disregard this document.

  • For power-sensitive devices, select the appropriate low power mode based on actual application scenarios. Note that device power consumption and response speed are typically inversely correlated. Lower power modes result in slower response times, impacting user experience.

  • For battery-powered devices, you can select power-off mode or AP persistent keep-alive mode to extend the battery life.

  • For ordinary electrical and lighting devices, the standard low power mode (operating current < 15 mA) is recommended.

Why does the power consumption not decrease significantly after setting the low power mode?

First, check whether you have called the relevant APIs correctly according to the example. Important note: The low power mode entry/exit APIs must be used in matched pairs to prevent power management instability. For more information, see this document.

  • For power-sensitive devices, select the appropriate low power mode based on actual application scenarios. Note that device power consumption and response speed are typically inversely correlated. Lower power modes result in slower response times, impacting user experience.

  • For battery-powered devices, you can select power-off mode or AP persistent keep-alive mode to extend the battery life.

  • For ordinary electrical and lighting devices, the standard low power mode (operating current < 15 mA) is recommended.