feat: Add NVS persistence for SCANRATE and PROBERATE commands
Both settings now save to NVS and restore on boot, matching the pattern used by other persisted config (rate, tx_power, etc).
This commit is contained in:
@@ -165,6 +165,10 @@ static int s_deauth_ring_count = 0;
|
||||
/* Power test */
|
||||
static volatile bool s_powertest_running = false;
|
||||
|
||||
/* Probe dedup rate (moved before config_load_nvs for NVS access) */
|
||||
#define PROBE_DEDUP_DEFAULT_US 10000000LL
|
||||
static int64_t s_probe_dedup_us = PROBE_DEDUP_DEFAULT_US;
|
||||
|
||||
/* --- NVS helpers --- */
|
||||
|
||||
static void config_load_nvs(void)
|
||||
@@ -224,6 +228,14 @@ static void config_load_nvs(void)
|
||||
if (nvs_get_i32(h, "flood_window", &flood_w) == ESP_OK && flood_w >= 1 && flood_w <= 300) {
|
||||
s_flood_window_s = (int)flood_w;
|
||||
}
|
||||
int32_t scan_r;
|
||||
if (nvs_get_i32(h, "scan_rate", &scan_r) == ESP_OK && scan_r >= 5 && scan_r <= 300) {
|
||||
s_ble_scan_interval_us = (int64_t)scan_r * 1000000LL;
|
||||
}
|
||||
int32_t probe_r;
|
||||
if (nvs_get_i32(h, "probe_rate", &probe_r) == ESP_OK && probe_r >= 1 && probe_r <= 300) {
|
||||
s_probe_dedup_us = (int64_t)probe_r * 1000000LL;
|
||||
}
|
||||
nvs_close(h);
|
||||
ESP_LOGI(TAG, "NVS loaded: hostname=%s rate=%d tx_power=%d adaptive=%d threshold=%.6f ble=%d target=%s:%d csi_mode=%d hybrid_n=%d",
|
||||
s_hostname, s_send_frequency, s_tx_power_dbm, s_adaptive, s_motion_threshold, s_ble_enabled,
|
||||
@@ -842,8 +854,7 @@ typedef struct {
|
||||
|
||||
/* Probe request deduplication: report each MAC at most once per N seconds */
|
||||
#define PROBE_DEDUP_SIZE 32
|
||||
#define PROBE_DEDUP_DEFAULT_US 10000000LL
|
||||
static int64_t s_probe_dedup_us = PROBE_DEDUP_DEFAULT_US;
|
||||
/* s_probe_dedup_us declared in globals section (before config_load_nvs) */
|
||||
|
||||
static struct {
|
||||
uint8_t mac[6];
|
||||
@@ -1403,11 +1414,12 @@ static int cmd_handle(const char *cmd, char *reply, size_t reply_size)
|
||||
return strlen(reply);
|
||||
}
|
||||
s_ble_scan_interval_us = (int64_t)val * 1000000LL;
|
||||
config_save_i32("scan_rate", (int32_t)val);
|
||||
if (s_ble_timer) {
|
||||
esp_timer_stop(s_ble_timer);
|
||||
esp_timer_start_periodic(s_ble_timer, s_ble_scan_interval_us);
|
||||
}
|
||||
snprintf(reply, reply_size, "OK SCANRATE %ds", val);
|
||||
snprintf(reply, reply_size, "OK SCANRATE %ds (saved)", val);
|
||||
return strlen(reply);
|
||||
}
|
||||
|
||||
@@ -1419,7 +1431,8 @@ static int cmd_handle(const char *cmd, char *reply, size_t reply_size)
|
||||
return strlen(reply);
|
||||
}
|
||||
s_probe_dedup_us = (int64_t)val * 1000000LL;
|
||||
snprintf(reply, reply_size, "OK PROBERATE %ds", val);
|
||||
config_save_i32("probe_rate", (int32_t)val);
|
||||
snprintf(reply, reply_size, "OK PROBERATE %ds (saved)", val);
|
||||
return strlen(reply);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user