From e0aa51f8bfd59427b8a595df9f7c88815e545b63 Mon Sep 17 00:00:00 2001 From: "tarun.kumar" Date: Wed, 12 Aug 2026 15:29:10 +0530 Subject: [PATCH] fix(wifi): Require RSSI gain before low-RSSI roam Low-RSSI roaming used determine_best_ap(0), so a 1 dB better AP was enough and nearby APs could ping-pong. Add ESP_WIFI_ROAMING_LOW_RSSI_ROAM_DIFF (default 5 dB) as hysteresis for that path. --- .../wifi_apps/roaming_app/include/esp_roaming.h | 1 + .../wifi_apps/roaming_app/src/Kconfig.roaming | 12 ++++++++++++ .../wifi_apps/roaming_app/src/esp_roaming_i.h | 1 + .../wifi_apps/roaming_app/src/roaming_app.c | 15 ++++++++++----- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/components/esp_wifi/wifi_apps/roaming_app/include/esp_roaming.h b/components/esp_wifi/wifi_apps/roaming_app/include/esp_roaming.h index d3d7acc4daa..cf974c306bc 100644 --- a/components/esp_wifi/wifi_apps/roaming_app/include/esp_roaming.h +++ b/components/esp_wifi/wifi_apps/roaming_app/include/esp_roaming.h @@ -20,6 +20,7 @@ struct roam_config { bool low_rssi_roam_trigger; int8_t low_rssi_threshold; uint8_t rssi_threshold_reduction_offset; + uint8_t low_rssi_roam_diff; bool scan_monitor; #if CONFIG_ESP_WIFI_ROAMING_PERIODIC_SCAN_MONITOR uint8_t scan_interval; diff --git a/components/esp_wifi/wifi_apps/roaming_app/src/Kconfig.roaming b/components/esp_wifi/wifi_apps/roaming_app/src/Kconfig.roaming index d566a902360..22bbd47029c 100644 --- a/components/esp_wifi/wifi_apps/roaming_app/src/Kconfig.roaming +++ b/components/esp_wifi/wifi_apps/roaming_app/src/Kconfig.roaming @@ -29,6 +29,18 @@ menu "Roaming triggers" Setting 0 here may cause station to be flooded with low rssi events, therefore that's not recommended to be kept. + config ESP_WIFI_ROAMING_LOW_RSSI_ROAM_DIFF + depends on ESP_WIFI_ROAMING_LOW_RSSI_ROAMING + int "RSSI difference b/w current AP and candidate AP for low RSSI roam" + range 1 99 + default 5 + help + Minimum RSSI improvement (in dB) required of a candidate AP before roaming + when triggered by the low RSSI event. A value of 1 keeps the previous behavior + (any strictly better AP). Higher values add hysteresis and reduce ping-pong + between nearby APs with similar RSSI. Prefer a small value here (e.g. 3-5); + use ESP_WIFI_ROAMING_SCAN_ROAM_RSSI_DIFF for larger proactive improvements. + config ESP_WIFI_ROAMING_PERIODIC_SCAN_MONITOR bool "Conduct periodic scans to check if a better AP is available" default y diff --git a/components/esp_wifi/wifi_apps/roaming_app/src/esp_roaming_i.h b/components/esp_wifi/wifi_apps/roaming_app/src/esp_roaming_i.h index 71e589cb40d..f66f1b7e135 100644 --- a/components/esp_wifi/wifi_apps/roaming_app/src/esp_roaming_i.h +++ b/components/esp_wifi/wifi_apps/roaming_app/src/esp_roaming_i.h @@ -29,6 +29,7 @@ extern "C" { #if LOW_RSSI_ROAMING_ENABLED #define ROAMING_LOW_RSSI_THRESHOLD CONFIG_ESP_WIFI_ROAMING_LOW_RSSI_THRESHOLD #define RSSI_THRESHOLD_REDUCTION_OFFSET CONFIG_ESP_WIFI_ROAMING_LOW_RSSI_OFFSET +#define LOW_RSSI_ROAM_DIFF CONFIG_ESP_WIFI_ROAMING_LOW_RSSI_ROAM_DIFF #endif /*LOW_RSSI_ROAMING_ENABLED*/ #ifndef CONFIG_ESP_WIFI_ROAMING_PERIODIC_SCAN_MONITOR diff --git a/components/esp_wifi/wifi_apps/roaming_app/src/roaming_app.c b/components/esp_wifi/wifi_apps/roaming_app/src/roaming_app.c index c774d69e692..ec077ddf0df 100644 --- a/components/esp_wifi/wifi_apps/roaming_app/src/roaming_app.c +++ b/components/esp_wifi/wifi_apps/roaming_app/src/roaming_app.c @@ -1342,7 +1342,7 @@ static void roaming_app_rssi_low_internal_handler(void *ctx, void *data) if (!roaming_app_get_ap_info(&g_roaming_app.current_bss.ap)) { g_roaming_app.current_bss.ap.rssi = event->rssi; } - determine_best_ap(0); + determine_best_ap(g_roaming_app.config.low_rssi_roam_diff - 1); int32_t next_threshold = g_roaming_app.current_low_rssi_threshold - g_roaming_app.config.rssi_threshold_reduction_offset; next_threshold = roaming_app_clamp_rssi_threshold(next_threshold); @@ -2097,8 +2097,11 @@ static esp_err_t init_config_params(void) g_roaming_app.config.backoff_time = ROAMING_BACKOFF_TIME; g_roaming_app.config.low_rssi_roam_trigger = LOW_RSSI_ROAMING_ENABLED; +#if LOW_RSSI_ROAMING_ENABLED g_roaming_app.config.low_rssi_threshold = ROAMING_LOW_RSSI_THRESHOLD; g_roaming_app.config.rssi_threshold_reduction_offset = RSSI_THRESHOLD_REDUCTION_OFFSET; + g_roaming_app.config.low_rssi_roam_diff = LOW_RSSI_ROAM_DIFF; +#endif /* LOW_RSSI_ROAMING_ENABLED */ g_roaming_app.config.scan_monitor = PERIODIC_SCAN_MONITORING; #if PERIODIC_SCAN_MONITORING @@ -2117,9 +2120,10 @@ static esp_err_t init_config_params(void) ESP_LOGD(ROAMING_TAG, "Roaming app config :"); - ESP_LOGD(ROAMING_TAG, "backoff time=%d low_rssi_roam_trigger=%d low_rssi_threshold=%d rssi_threshold_reduction_offset=%d", + ESP_LOGD(ROAMING_TAG, "backoff time=%d low_rssi_roam_trigger=%d low_rssi_threshold=%d rssi_threshold_reduction_offset=%d low_rssi_roam_diff=%d", g_roaming_app.config.backoff_time, g_roaming_app.config.low_rssi_roam_trigger, - g_roaming_app.config.low_rssi_threshold, g_roaming_app.config.rssi_threshold_reduction_offset); + g_roaming_app.config.low_rssi_threshold, g_roaming_app.config.rssi_threshold_reduction_offset, + g_roaming_app.config.low_rssi_roam_diff); #if PERIODIC_SCAN_MONITORING ESP_LOGD(ROAMING_TAG, "scan_monitor=%d scan_interval=%d scan_rssi_threshold=%d scan_rssi_diff=%d", @@ -2421,9 +2425,10 @@ static int update_config_params(void *data) ESP_LOGI(ROAMING_TAG, "Updated Roaming app config :"); - ESP_LOGI(ROAMING_TAG, "backoff time=%d low_rssi_roam_trigger=%d low_rssi_threshold=%d rssi_threshold_reduction_offset=%d", + ESP_LOGI(ROAMING_TAG, "backoff time=%d low_rssi_roam_trigger=%d low_rssi_threshold=%d rssi_threshold_reduction_offset=%d low_rssi_roam_diff=%d", g_roaming_app.config.backoff_time, g_roaming_app.config.low_rssi_roam_trigger, - g_roaming_app.config.low_rssi_threshold, g_roaming_app.config.rssi_threshold_reduction_offset); + g_roaming_app.config.low_rssi_threshold, g_roaming_app.config.rssi_threshold_reduction_offset, + g_roaming_app.config.low_rssi_roam_diff); #if PERIODIC_SCAN_MONITORING ESP_LOGI(ROAMING_TAG, "scan_monitor=%d scan_interval=%d scan_rssi_threshold=%d scan_rssi_diff=%d",