Skip to content

Commit 8a84748

Browse files
committed
fix(firmware): use NVS node_id instead of Kconfig constant (#279)
CONFIG_CSI_NODE_ID (compile-time, always 1) was hardcoded in 6 places: CSI frame serialization, compressed frames, vitals packets, WASM output packets, and display UI. NVS provisioning wrote the correct node_id but it was never used at runtime. Fixed all occurrences to use g_nvs_config.node_id: - csi_collector.c: frame header + log message - edge_processing.c: compressed frame + vitals packet - wasm_runtime.c: WASM output packet - display_ui.c: system info display This means --node-id 0/1/2 provisioning now actually works for multi-node mesh deployments. Closes #279 Co-Authored-By: claude-flow <ruv@ruv.net>
1 parent 578d84c commit 8a84748

File tree

4 files changed

+17
-23
lines changed

4 files changed

+17
-23
lines changed

firmware/esp32-csi-node/main/csi_collector.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ size_t csi_serialize_frame(const wifi_csi_info_t *info, uint8_t *buf, size_t buf
117117
uint32_t magic = CSI_MAGIC;
118118
memcpy(&buf[0], &magic, 4);
119119

120-
/* Node ID */
121-
buf[4] = (uint8_t)CONFIG_CSI_NODE_ID;
120+
/* Node ID (from NVS runtime config, not compile-time Kconfig) */
121+
buf[4] = g_nvs_config.node_id;
122122

123123
/* Number of antennas */
124124
buf[5] = n_antennas;
@@ -273,7 +273,7 @@ void csi_collector_init(void)
273273
}
274274

275275
ESP_LOGI(TAG, "CSI collection initialized (node_id=%d, channel=%u)",
276-
CONFIG_CSI_NODE_ID, (unsigned)csi_channel);
276+
g_nvs_config.node_id, (unsigned)csi_channel);
277277
}
278278

279279
/* ---- ADR-029: Channel hopping ---- */

firmware/esp32-csi-node/main/display_ui.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
*/
88

99
#include "display_ui.h"
10+
#include "nvs_config.h"
1011
#include "sdkconfig.h"
1112

13+
extern nvs_config_t g_nvs_config;
14+
1215
#if CONFIG_DISPLAY_ENABLE
1316

1417
#include <stdio.h>
@@ -347,11 +350,7 @@ void display_ui_update(void)
347350
{
348351
char buf[48];
349352

350-
#ifdef CONFIG_CSI_NODE_ID
351-
snprintf(buf, sizeof(buf), "Node: %d", CONFIG_CSI_NODE_ID);
352-
#else
353-
snprintf(buf, sizeof(buf), "Node: --");
354-
#endif
353+
snprintf(buf, sizeof(buf), "Node: %d", g_nvs_config.node_id);
355354
lv_label_set_text(s_sys_node, buf);
356355

357356
snprintf(buf, sizeof(buf), "Heap: %lu KB free",

firmware/esp32-csi-node/main/edge_processing.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
*/
1919

2020
#include "edge_processing.h"
21+
#include "nvs_config.h"
2122
#include "mmwave_sensor.h"
23+
24+
/* Runtime config — declared in main.c, loaded from NVS at boot. */
25+
extern nvs_config_t g_nvs_config;
2226
#include "wasm_runtime.h"
2327
#include "stream_sender.h"
2428

@@ -426,11 +430,7 @@ static void send_compressed_frame(const uint8_t *iq_data, uint16_t iq_len,
426430
uint32_t magic = EDGE_COMPRESSED_MAGIC;
427431
memcpy(&pkt[0], &magic, 4);
428432

429-
#ifdef CONFIG_CSI_NODE_ID
430-
pkt[4] = (uint8_t)CONFIG_CSI_NODE_ID;
431-
#else
432-
pkt[4] = 0;
433-
#endif
433+
pkt[4] = g_nvs_config.node_id;
434434
pkt[5] = channel;
435435
memcpy(&pkt[6], &iq_len, 2);
436436
memcpy(&pkt[8], &comp_len, 2);
@@ -548,11 +548,7 @@ static void send_vitals_packet(void)
548548
memset(&pkt, 0, sizeof(pkt));
549549

550550
pkt.magic = EDGE_VITALS_MAGIC;
551-
#ifdef CONFIG_CSI_NODE_ID
552-
pkt.node_id = (uint8_t)CONFIG_CSI_NODE_ID;
553-
#else
554-
pkt.node_id = 0;
555-
#endif
551+
pkt.node_id = g_nvs_config.node_id;
556552

557553
pkt.flags = 0;
558554
if (s_presence_detected) pkt.flags |= 0x01;

firmware/esp32-csi-node/main/wasm_runtime.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
#include "sdkconfig.h"
1414
#include "wasm_runtime.h"
15+
#include "nvs_config.h"
16+
17+
extern nvs_config_t g_nvs_config;
1518

1619
#if defined(CONFIG_WASM_ENABLE) && defined(WASM3_AVAILABLE)
1720

@@ -380,11 +383,7 @@ static void send_wasm_output(uint8_t slot_id)
380383
memset(&pkt, 0, sizeof(pkt));
381384

382385
pkt.magic = WASM_OUTPUT_MAGIC;
383-
#ifdef CONFIG_CSI_NODE_ID
384-
pkt.node_id = (uint8_t)CONFIG_CSI_NODE_ID;
385-
#else
386-
pkt.node_id = 0;
387-
#endif
386+
pkt.node_id = g_nvs_config.node_id;
388387
pkt.module_id = slot_id;
389388
pkt.event_count = n_filtered;
390389

0 commit comments

Comments
 (0)