From 3587c5230c1943cddb238d35a52b4bb8ae5e33c9 Mon Sep 17 00:00:00 2001 From: "Deomid \"rojer\" Ryabkov" Date: Sun, 20 Jun 2021 21:35:39 +0100 Subject: [PATCH] Fix RSSI reporting --- src/mgos_wifi_sta.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mgos_wifi_sta.c b/src/mgos_wifi_sta.c index 58716f3..9f90f3b 100644 --- a/src/mgos_wifi_sta.c +++ b/src/mgos_wifi_sta.c @@ -461,7 +461,6 @@ static void mgos_wifi_sta_run(int wifi_ev, void *ev_data, bool timeout) { /* If we are roaming and have no good candidate, go back. */ int cur_rssi = mgos_wifi_sta_get_rssi(); bool ok = false; - s_rssi_info.val <<= 8; if (ape == NULL || ape->rssi == 0) { LOG(LL_INFO, ("No candidate APs")); } else if (s_cur_entry != NULL && memcmp(s_cur_entry->bssid, ape->bssid, @@ -590,14 +589,15 @@ static void mgos_wifi_sta_run(int wifi_ev, void *ev_data, bool timeout) { sum += s_rssi_info.samples[i]; } int avg_rssi = sum / (int) ARRAY_SIZE(s_rssi_info.samples); - LOG(LL_INFO, ("Avg RSSI %d", avg_rssi)); int64_t now = mgos_uptime_micros(); - if (avg_rssi < roam_rssi_thr && - (now - s_last_roam_attempt > roam_intvl * 1000000)) { - s_roaming = true; - s_state = WIFI_STA_SCAN; - mgos_wifi_sta_set_timeout(true /* run_now */); - s_last_roam_attempt = mgos_uptime_micros(); + if (now - s_last_roam_attempt > roam_intvl * 1000000) { + LOG(LL_INFO, ("Avg RSSI %d", avg_rssi)); + if (avg_rssi < roam_rssi_thr) { + s_roaming = true; + s_state = WIFI_STA_SCAN; + s_last_roam_attempt = now; + mgos_wifi_sta_set_timeout(true /* run_now */); + } } } }