feat: Add NVS and partition info to STATUS response
Some checks failed
Lint & Build / C/C++ Static Analysis (push) Failing after 38s
Lint & Build / Security Flaw Analysis (push) Successful in 20s
Lint & Build / Secret Scanning (push) Successful in 5s
Lint & Build / Shell Script Analysis (push) Successful in 7s
Lint & Build / Build Firmware (push) Successful in 2m12s
Lint & Build / Deploy to ESP Fleet (push) Successful in 3m31s

- nvs_used: NVS entries in use
- nvs_free: free NVS entries
- nvs_total: total NVS entries
- part_size: running partition size in bytes
This commit is contained in:
user
2026-02-05 21:33:20 +01:00
parent f87ddec742
commit 4b3697c8e6

View File

@@ -35,6 +35,7 @@
#include "esp_heap_caps.h"
#include "esp_ota_ops.h"
#include "esp_https_ota.h"
#include "esp_partition.h"
#include "esp_http_client.h"
#include "driver/gpio.h"
#include "soc/soc_caps.h"
@@ -1524,12 +1525,29 @@ static int cmd_handle(const char *cmd, char *reply, size_t reply_size)
const char *csi_mode_str = (s_csi_mode == CSI_MODE_COMPACT) ? "compact" :
(s_csi_mode == CSI_MODE_HYBRID) ? "hybrid" : "raw";
/* NVS stats */
nvs_stats_t nvs_stats = {0};
nvs_get_stats("nvs", &nvs_stats);
/* Partition info */
const esp_partition_t *running = esp_ota_get_running_partition();
uint32_t part_size = running ? running->size : 0;
uint32_t app_size = 0;
if (running) {
esp_app_desc_t desc;
if (esp_ota_get_partition_description(running, &desc) == ESP_OK) {
/* App size not directly available, use partition size */
app_size = part_size;
}
}
snprintf(reply, reply_size,
"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"
" csi_mode=%s hybrid_n=%d auth=%s flood_thresh=%d/%d powersave=%s"
" presence=%s pr_score=%.4f chanscan=%s",
" presence=%s pr_score=%.4f chanscan=%s"
" nvs_used=%lu nvs_free=%lu nvs_total=%lu part_size=%lu",
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,
@@ -1542,7 +1560,11 @@ static int cmd_handle(const char *cmd, char *reply, size_t reply_size)
s_flood_thresh, s_flood_window_s,
s_powersave ? "on" : "off",
s_presence_enabled ? "on" : "off", s_pr_last_score,
s_chanscan_enabled ? "on" : "off");
s_chanscan_enabled ? "on" : "off",
(unsigned long)nvs_stats.used_entries,
(unsigned long)nvs_stats.free_entries,
(unsigned long)nvs_stats.total_entries,
(unsigned long)part_size);
return strlen(reply);
}