forked from philippe44/squeezelite-esp32
-
Notifications
You must be signed in to change notification settings - Fork 193
Add configurable WiFi power save mode via NVS key "wifi_ps" #552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gnoe-gnoe
wants to merge
1
commit into
sle118:master-v4.3
Choose a base branch
from
gnoe-gnoe:feature/wifi-ps-nvs-setting
base: master-v4.3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -474,6 +474,17 @@ esp_netif_t* network_wifi_get_interface() { | |
| esp_netif_t* network_wifi_get_ap_interface() { | ||
| return wifi_ap_netif; | ||
| } | ||
| static wifi_ps_type_t network_wifi_get_ps_mode() { | ||
| uint16_t ps_mode = DEFAULT_STA_POWER_SAVE; | ||
| config_get_uint16t_from_str("wifi_ps", &ps_mode, DEFAULT_STA_POWER_SAVE); | ||
| if (ps_mode > WIFI_PS_MAX_MODEM) { | ||
| ESP_LOGW(TAG, "Invalid wifi_ps value %d, defaulting to %d", ps_mode, DEFAULT_STA_POWER_SAVE); | ||
| ps_mode = DEFAULT_STA_POWER_SAVE; | ||
| } | ||
| ESP_LOGI(TAG, "WiFi power save mode: %d (0=none, 1=min_modem, 2=max_modem)", ps_mode); | ||
| return (wifi_ps_type_t)ps_mode; | ||
| } | ||
|
|
||
| esp_err_t network_wifi_set_sta_mode() { | ||
| if (!wifi_netif) { | ||
| ESP_LOGE(TAG, "Wifi not initialized. Cannot set sta mode"); | ||
|
|
@@ -488,6 +499,8 @@ esp_err_t network_wifi_set_sta_mode() { | |
| err = esp_wifi_start(); | ||
| if (err != ESP_OK) { | ||
| ESP_LOGE(TAG, "Error starting wifi: %s", esp_err_to_name(err)); | ||
| } else { | ||
| ESP_ERROR_CHECK_WITHOUT_ABORT(esp_wifi_set_ps(network_wifi_get_ps_mode())); | ||
| } | ||
| } | ||
| return err; | ||
|
|
@@ -951,9 +964,10 @@ esp_netif_t* network_wifi_config_ap() { | |
| } | ||
|
|
||
| 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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| if ((err = esp_wifi_set_ps(DEFAULT_STA_POWER_SAVE)) != ESP_OK) /* stop AP DHCP server */ | ||
| if ((err = esp_wifi_set_ps(ps_mode)) != ESP_OK) | ||
| { | ||
| ESP_LOGE(TAG, "%s failed. Error %s", msg, esp_err_to_name(err)); | ||
| return wifi_ap_netif; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
ps_modevariable is initialized, but its value is immediately overwritten byconfig_get_uint16t_from_strin 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.