Skip to content

Add configurable WiFi power save mode via NVS key "wifi_ps"#552

Open
gnoe-gnoe wants to merge 1 commit intosle118:master-v4.3from
gnoe-gnoe:feature/wifi-ps-nvs-setting
Open

Add configurable WiFi power save mode via NVS key "wifi_ps"#552
gnoe-gnoe wants to merge 1 commit intosle118:master-v4.3from
gnoe-gnoe:feature/wifi-ps-nvs-setting

Conversation

@gnoe-gnoe
Copy link

WiFi power save was hardcoded to WIFI_PS_MIN_MODEM, which can cause watchdog timeouts and CCMP replay errors when routers reset overnight.

The power save mode is now configurable via the NVS key "wifi_ps":
0 = WIFI_PS_NONE (no power management)
1 = WIFI_PS_MIN_MODEM (default, minimum power save)
2 = WIFI_PS_MAX_MODEM (maximum power save)

Also explicitly calls esp_wifi_set_ps() in STA mode (previously only called in AP mode).

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the WiFi management system by introducing a user-configurable power save mode. Previously, the power save setting was fixed, which could lead to connectivity and stability problems in certain scenarios. The update allows the system to dynamically adjust its power consumption behavior based on a setting stored in Non-Volatile Storage (NVS), providing greater control and improving overall reliability for connected devices.

Highlights

  • Configurable WiFi Power Save: Introduced a configurable WiFi power save mode, allowing users to select between WIFI_PS_NONE, WIFI_PS_MIN_MODEM, and WIFI_PS_MAX_MODEM.
  • NVS Key for Configuration: The power save mode can now be set via the NVS key "wifi_ps", providing flexibility beyond the hardcoded default.
  • STA Mode Power Save Application: Explicitly applied the configured power save mode when the device operates in STA (Station) mode, addressing previous behavior where it was only applied in AP mode.
  • Addressing Stability Issues: This change aims to mitigate issues like watchdog timeouts and CCMP replay errors that could occur with the previously hardcoded WIFI_PS_MIN_MODEM setting, especially during router resets.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • components/wifi-manager/network_manager.h
    • Updated comments for DEFAULT_STA_POWER_SAVE to clarify available modes (WIFI_PS_NONE, WIFI_PS_MIN_MODEM, WIFI_PS_MAX_MODEM) and mention the NVS override capability.
  • components/wifi-manager/network_wifi.c
    • Added a new static function network_wifi_get_ps_mode to retrieve the WiFi power save mode from NVS, validate it, and return the appropriate wifi_ps_type_t.
    • Modified network_wifi_set_sta_mode to explicitly call esp_wifi_set_ps() using the value returned by network_wifi_get_ps_mode() after WiFi is started.
    • Updated network_wifi_config_ap to utilize the configurable power save mode by calling network_wifi_get_ps_mode() before setting the power save type.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

WiFi power save was hardcoded to WIFI_PS_MIN_MODEM, which can cause
watchdog timeouts and CCMP replay errors when routers reset overnight.

The power save mode is now configurable via the NVS key "wifi_ps":
  0 = WIFI_PS_NONE (no power management)
  1 = WIFI_PS_MIN_MODEM (default, minimum power save)
  2 = WIFI_PS_MAX_MODEM (maximum power save)

Also explicitly calls esp_wifi_set_ps() in STA mode (previously only
called in AP mode).
@gnoe-gnoe gnoe-gnoe force-pushed the feature/wifi-ps-nvs-setting branch from a09510e to d384f38 Compare March 9, 2026 12:46
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a configurable WiFi power save mode via an NVS key, which is a valuable enhancement for flexibility. The implementation is sound, creating a new function to retrieve the setting and applying it during WiFi setup. I have provided a couple of minor suggestions to streamline the code and reduce log redundancy.

Comment on lines +478 to +479
uint16_t ps_mode = DEFAULT_STA_POWER_SAVE;
config_get_uint16t_from_str("wifi_ps", &ps_mode, DEFAULT_STA_POWER_SAVE);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ps_mode variable is initialized, but its value is immediately overwritten by config_get_uint16t_from_str in the next line, as this function handles setting a default value if the NVS key is not found. The initial assignment is redundant and can be removed to make the code slightly cleaner.

    uint16_t ps_mode;
    config_get_uint16t_from_str("wifi_ps", &ps_mode, DEFAULT_STA_POWER_SAVE);

msg = "Setting wifi power save";
ESP_LOGD(TAG, "%s (%d)", msg, DEFAULT_STA_POWER_SAVE);
wifi_ps_type_t ps_mode = network_wifi_get_ps_mode();
ESP_LOGD(TAG, "%s (%d)", msg, ps_mode);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The network_wifi_get_ps_mode() function, called on the previous line, already logs the selected power save mode at the INFO level. This ESP_LOGD call is therefore redundant and can be removed to avoid duplicate log entries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants