Skip to content

Commit

Permalink
Fix RSSI reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
rojer committed Jun 20, 2021
1 parent 013cfe8 commit 3587c52
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/mgos_wifi_sta.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 */);
}
}
}
}
Expand Down

0 comments on commit 3587c52

Please sign in to comment.