diff --git a/get-started/csi_recv_router/main/app_main.c b/get-started/csi_recv_router/main/app_main.c index 3a15967..d58b2cf 100644 --- a/get-started/csi_recv_router/main/app_main.c +++ b/get-started/csi_recv_router/main/app_main.c @@ -91,6 +91,9 @@ static volatile int64_t s_identify_end_time = 0; static volatile bool s_ota_in_progress = false; static volatile uint32_t s_csi_count = 0; static volatile bool s_wifi_connected = false; +static volatile int8_t s_rssi_min = 0; +static volatile int8_t s_rssi_max = -128; +static uint32_t s_boot_count = 0; /* Adaptive sampling */ #define WANDER_WINDOW 50 @@ -174,6 +177,18 @@ static void config_load_nvs(void) } else { ESP_LOGI(TAG, "NVS: no saved config, using defaults"); } + + /* Boot counter — always increment, even on first boot */ + nvs_handle_t bh; + if (nvs_open("csi_config", NVS_READWRITE, &bh) == ESP_OK) { + int32_t bc = 0; + nvs_get_i32(bh, "boot_count", &bc); + s_boot_count = (uint32_t)(bc + 1); + nvs_set_i32(bh, "boot_count", (int32_t)s_boot_count); + nvs_commit(bh); + nvs_close(bh); + ESP_LOGI(TAG, "Boot count: %lu", (unsigned long)s_boot_count); + } } static esp_err_t config_save_i32(const char *key, int32_t value) @@ -299,6 +314,11 @@ static void wifi_csi_rx_cb(void *ctx, wifi_csi_info_t *info) s_last_csi_time = esp_timer_get_time(); const wifi_pkt_rx_ctrl_t *rx_ctrl = &info->rx_ctrl; + + /* Track RSSI min/max */ + int8_t rssi = rx_ctrl->rssi; + if (s_csi_count == 0 || rssi < s_rssi_min) s_rssi_min = rssi; + if (s_csi_count == 0 || rssi > s_rssi_max) s_rssi_max = rssi; float compensate_gain = 1.0f; static uint8_t agc_gain = 0; static int8_t fft_gain = 0; @@ -860,8 +880,10 @@ static int cmd_handle(const char *cmd, char *reply, size_t reply_size) wifi_ap_record_t ap; int rssi = 0; + int channel = 0; if (esp_wifi_sta_get_ap_info(&ap) == ESP_OK) { rssi = ap.rssi; + channel = ap.primary; } const esp_app_desc_t *app_desc = esp_app_get_description(); @@ -873,6 +895,8 @@ static int cmd_handle(const char *cmd, char *reply, size_t reply_size) } #endif + int actual_rate = (up > 0) ? (int)((uint64_t)s_csi_count / (uint64_t)up) : 0; + char uptime_str[32]; if (days > 0) { snprintf(uptime_str, sizeof(uptime_str), "%dd%dh%dm", days, hours, mins); @@ -883,12 +907,16 @@ static int cmd_handle(const char *cmd, char *reply, size_t reply_size) } snprintf(reply, reply_size, - "OK STATUS uptime=%s uptime_s=%lld heap=%lu rssi=%d tx_power=%d rate=%d hostname=%s version=%s adaptive=%s motion=%d ble=%s target=%s:%d temp=%.1f csi_count=%lu", - uptime_str, (long long)up, (unsigned long)heap, rssi, (int)s_tx_power_dbm, - s_send_frequency, s_hostname, app_desc->version, + "OK STATUS uptime=%s uptime_s=%lld heap=%lu rssi=%d channel=%d tx_power=%d rate=%d csi_rate=%d" + " hostname=%s version=%s adaptive=%s motion=%d ble=%s target=%s:%d" + " temp=%.1f csi_count=%lu boots=%lu rssi_min=%d rssi_max=%d", + uptime_str, (long long)up, (unsigned long)heap, rssi, channel, (int)s_tx_power_dbm, + s_send_frequency, actual_rate, + s_hostname, app_desc->version, s_adaptive ? "on" : "off", s_motion_detected ? 1 : 0, s_ble_enabled ? "on" : "off", s_target_ip, s_target_port, - chip_temp, (unsigned long)s_csi_count); + chip_temp, (unsigned long)s_csi_count, (unsigned long)s_boot_count, + (int)s_rssi_min, (int)s_rssi_max); return strlen(reply); }