Skip to content

On wifi set_config only update sta and ap config when something changes#5849

Open
mlandauer wants to merge 2 commits into
esp-rs:mainfrom
mlandauer:wifi_set_config_fix
Open

On wifi set_config only update sta and ap config when something changes#5849
mlandauer wants to merge 2 commits into
esp-rs:mainfrom
mlandauer:wifi_set_config_fix

Conversation

@mlandauer

Copy link
Copy Markdown

Submission Checklist 📝

  • I have updated existing examples or added new ones (if applicable).
  • I have used cargo xtask fmt-packages command to ensure that all changed code is formatted correctly.
  • I have added changelog entries and/or migration guide notes in the sections below, or I will ask a maintainer to add the skip-changelog or manual-changelog label as appropriate.
  • My changes are in accordance to the esp-rs developer guidelines

Extra:

Pull Request Details 📖

Description

This avoids needless connection interruptions when calling WifiController::set_config. Most useful in combined AP/Station mode when setting the config of the station and you don't want to interrupt the AP connection.

A common solution for provisioning a device is you start the wifi in a combined access point (AP) and station mode. This way the user can connect to the AP, access a web server running on the device, choose a wifi network and the device then uses the station to try connecting to that network.

Currently, when you're running in a combined AP/station mode and you update the station part of the config under the hood it will update the AP config as well even though nothing has changed there. This causes a connection interruption on the AP side which isn't always necessary.

The solution is simply to update the AP and station parts of the config separately (as they currently are) but only apply a change if it the configuration is different than the current state.

This PR depends on a currently open PR in esp-wifi-sys. If that change isn't okay I'm obviously happy to reimplement this PR so that it doesn't depend on PartialEq being added to a few structs though it would obviously make it a little bit more long-winded! :-)

Since this is my first PR on this project I have undoubtedly done a number of things wrong.

Things I'm most likely to have done wrong:

  • Added consts TOTAL_HW_ENCRYPT_KEYS and AP_MAX_CONNECTIONS that matches my best understanding from the docs and from testing on an esp32 how the max connection for the AP and ESP-NOW are shared. See https://github.com/espressif/esp-idf/blob/master/components/esp_wifi/Kconfig#L589
  • Are these values available somewhere else? I've looked up and down but I see nothing that looks like it.
  • Should these consts instead be made available in esp-wifi-sys somehow rather than being hardcoded here?

Testing

Tested with esp32 hardware. A browser client connected to the device's soft-AP stays connected across repeated set_config calls with an unchanged config, where before it would get disconnected.


Changelog

esp-radio

  • Fixed: WifiController set_config only updates AP and STA config on changes

mlandauer added 2 commits July 6, 2026 19:44
This avoids needless connection interruptions, Most useful in combined
AP/Station mode when setting the config of the station and you don't
want to interrupt the AP connection.
@bjoernQ

bjoernQ commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

This generally makes sense I guess.

The effective values from kconfig should be available as constants prefixed by CONFIG_, e.g. CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM

❯ rg "pub const CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM"
esp-wifi-sys-esp32s3\src\include.rs
1050:pub const CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM: u32 = 7;

esp-wifi-sys-esp32c3\src\include.rs
927:pub const CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM: u32 = 7;

esp-wifi-sys-esp32c61\src\include.rs
860:pub const CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM: u32 = 7;

esp-wifi-sys-esp32c2\src\include.rs
837:pub const CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM: u32 = 2;

esp-wifi-sys-esp32s2\src\include.rs
810:pub const CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM: u32 = 7;

esp-wifi-sys-esp32c6\src\include.rs
955:pub const CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM: u32 = 7;

esp-wifi-sys-esp32\src\include.rs
871:pub const CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM: u32 = 7;

esp-wifi-sys-esp32c5\src\include.rs
1021:pub const CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM: u32 = 7;

❯ rg ESP_WIFI_MAX_CONN_NUM
esp-wifi-sys-esp32\src\include.rs
1401:pub const ESP_WIFI_MAX_CONN_NUM: u32 = 15;

esp-wifi-sys-esp32s2\src\include.rs
1277:pub const ESP_WIFI_MAX_CONN_NUM: u32 = 15;

esp-wifi-sys-esp32s3\src\include.rs
1580:pub const ESP_WIFI_MAX_CONN_NUM: u32 = 15;

esp-wifi-sys-esp32c3\src\include.rs
1441:pub const ESP_WIFI_MAX_CONN_NUM: u32 = 10;

esp-wifi-sys-esp32c6\src\include.rs
1411:pub const ESP_WIFI_MAX_CONN_NUM: u32 = 10;

esp-wifi-sys-esp32c5\src\include.rs
1482:pub const ESP_WIFI_MAX_CONN_NUM: u32 = 10;

esp-wifi-sys-esp32h2\src\include.rs
1530:pub const ESP_WIFI_MAX_CONN_NUM: u32 = 15;

esp-wifi-sys-esp32c2\src\include.rs
1339:pub const ESP_WIFI_MAX_CONN_NUM: u32 = 4;

PartialEq shouldn't be a problem

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