fix(docker): Update Dockerfile paths from src/ to v1/src/

The source code was moved to v1/src/ but the Dockerfile still
referenced src/ directly, causing build failures. Updated all
COPY paths, uvicorn module paths, test paths, and bandit scan
paths. Also added missing v1/__init__.py for Python module
resolution.

Fixes #33

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
ruv
2026-02-28 13:38:21 -05:00
parent f460097a2f
commit 7872987ee6
45 changed files with 358 additions and 7992 deletions

View File

@@ -1,4 +1,4 @@
idf_component_register(
SRCS "main.c" "csi_collector.c" "stream_sender.c"
SRCS "main.c" "csi_collector.c" "stream_sender.c" "nvs_config.c"
INCLUDE_DIRS "."
)

View File

@@ -20,9 +20,13 @@
#include "csi_collector.h"
#include "stream_sender.h"
#include "nvs_config.h"
static const char *TAG = "main";
/* Runtime configuration (loaded from NVS or Kconfig defaults). */
static nvs_config_t s_cfg;
/* Event group bits */
#define WIFI_CONNECTED_BIT BIT0
#define WIFI_FAIL_BIT BIT1
@@ -72,14 +76,14 @@ static void wifi_init_sta(void)
wifi_config_t wifi_config = {
.sta = {
.ssid = CONFIG_CSI_WIFI_SSID,
#ifdef CONFIG_CSI_WIFI_PASSWORD
.password = CONFIG_CSI_WIFI_PASSWORD,
#endif
.threshold.authmode = WIFI_AUTH_WPA2_PSK,
},
};
/* Copy runtime SSID/password from NVS config */
strncpy((char *)wifi_config.sta.ssid, s_cfg.wifi_ssid, sizeof(wifi_config.sta.ssid) - 1);
strncpy((char *)wifi_config.sta.password, s_cfg.wifi_password, sizeof(wifi_config.sta.password) - 1);
/* If password is empty, use open auth */
if (strlen((char *)wifi_config.sta.password) == 0) {
wifi_config.sta.threshold.authmode = WIFI_AUTH_OPEN;
@@ -89,7 +93,7 @@ static void wifi_init_sta(void)
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
ESP_LOGI(TAG, "WiFi STA initialized, connecting to SSID: %s", CONFIG_CSI_WIFI_SSID);
ESP_LOGI(TAG, "WiFi STA initialized, connecting to SSID: %s", s_cfg.wifi_ssid);
/* Wait for connection */
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
@@ -105,8 +109,6 @@ static void wifi_init_sta(void)
void app_main(void)
{
ESP_LOGI(TAG, "ESP32-S3 CSI Node (ADR-018) — Node ID: %d", CONFIG_CSI_NODE_ID);
/* Initialize NVS */
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
@@ -115,11 +117,16 @@ void app_main(void)
}
ESP_ERROR_CHECK(ret);
/* Load runtime config (NVS overrides Kconfig defaults) */
nvs_config_load(&s_cfg);
ESP_LOGI(TAG, "ESP32-S3 CSI Node (ADR-018) — Node ID: %d", s_cfg.node_id);
/* Initialize WiFi STA */
wifi_init_sta();
/* Initialize UDP sender */
if (stream_sender_init() != 0) {
/* Initialize UDP sender with runtime target */
if (stream_sender_init_with(s_cfg.target_ip, s_cfg.target_port) != 0) {
ESP_LOGE(TAG, "Failed to initialize UDP sender");
return;
}
@@ -128,7 +135,7 @@ void app_main(void)
csi_collector_init();
ESP_LOGI(TAG, "CSI streaming active → %s:%d",
CONFIG_CSI_TARGET_IP, CONFIG_CSI_TARGET_PORT);
s_cfg.target_ip, s_cfg.target_port);
/* Main loop — keep alive */
while (1) {

View File

@@ -0,0 +1,88 @@
/**
* @file nvs_config.c
* @brief Runtime configuration via NVS (Non-Volatile Storage).
*
* Checks NVS namespace "csi_cfg" for keys: ssid, password, target_ip,
* target_port, node_id. Falls back to Kconfig defaults when absent.
*/
#include "nvs_config.h"
#include <string.h>
#include "esp_log.h"
#include "nvs_flash.h"
#include "nvs.h"
#include "sdkconfig.h"
static const char *TAG = "nvs_config";
void nvs_config_load(nvs_config_t *cfg)
{
/* Start with Kconfig compiled defaults */
strncpy(cfg->wifi_ssid, CONFIG_CSI_WIFI_SSID, NVS_CFG_SSID_MAX - 1);
cfg->wifi_ssid[NVS_CFG_SSID_MAX - 1] = '\0';
#ifdef CONFIG_CSI_WIFI_PASSWORD
strncpy(cfg->wifi_password, CONFIG_CSI_WIFI_PASSWORD, NVS_CFG_PASS_MAX - 1);
cfg->wifi_password[NVS_CFG_PASS_MAX - 1] = '\0';
#else
cfg->wifi_password[0] = '\0';
#endif
strncpy(cfg->target_ip, CONFIG_CSI_TARGET_IP, NVS_CFG_IP_MAX - 1);
cfg->target_ip[NVS_CFG_IP_MAX - 1] = '\0';
cfg->target_port = (uint16_t)CONFIG_CSI_TARGET_PORT;
cfg->node_id = (uint8_t)CONFIG_CSI_NODE_ID;
/* Try to override from NVS */
nvs_handle_t handle;
esp_err_t err = nvs_open("csi_cfg", NVS_READONLY, &handle);
if (err != ESP_OK) {
ESP_LOGI(TAG, "No NVS config found, using compiled defaults");
return;
}
size_t len;
char buf[NVS_CFG_PASS_MAX];
/* WiFi SSID */
len = sizeof(buf);
if (nvs_get_str(handle, "ssid", buf, &len) == ESP_OK && len > 1) {
strncpy(cfg->wifi_ssid, buf, NVS_CFG_SSID_MAX - 1);
cfg->wifi_ssid[NVS_CFG_SSID_MAX - 1] = '\0';
ESP_LOGI(TAG, "NVS override: ssid=%s", cfg->wifi_ssid);
}
/* WiFi password */
len = sizeof(buf);
if (nvs_get_str(handle, "password", buf, &len) == ESP_OK) {
strncpy(cfg->wifi_password, buf, NVS_CFG_PASS_MAX - 1);
cfg->wifi_password[NVS_CFG_PASS_MAX - 1] = '\0';
ESP_LOGI(TAG, "NVS override: password=***");
}
/* Target IP */
len = sizeof(buf);
if (nvs_get_str(handle, "target_ip", buf, &len) == ESP_OK && len > 1) {
strncpy(cfg->target_ip, buf, NVS_CFG_IP_MAX - 1);
cfg->target_ip[NVS_CFG_IP_MAX - 1] = '\0';
ESP_LOGI(TAG, "NVS override: target_ip=%s", cfg->target_ip);
}
/* Target port */
uint16_t port_val;
if (nvs_get_u16(handle, "target_port", &port_val) == ESP_OK) {
cfg->target_port = port_val;
ESP_LOGI(TAG, "NVS override: target_port=%u", cfg->target_port);
}
/* Node ID */
uint8_t node_val;
if (nvs_get_u8(handle, "node_id", &node_val) == ESP_OK) {
cfg->node_id = node_val;
ESP_LOGI(TAG, "NVS override: node_id=%u", cfg->node_id);
}
nvs_close(handle);
}

View File

@@ -0,0 +1,39 @@
/**
* @file nvs_config.h
* @brief Runtime configuration via NVS (Non-Volatile Storage).
*
* Reads WiFi credentials and aggregator target from NVS.
* Falls back to compile-time Kconfig defaults if NVS keys are absent.
* This allows a single firmware binary to be shipped and configured
* per-device using the provisioning script.
*/
#ifndef NVS_CONFIG_H
#define NVS_CONFIG_H
#include <stdint.h>
/** Maximum lengths for NVS string fields. */
#define NVS_CFG_SSID_MAX 33
#define NVS_CFG_PASS_MAX 65
#define NVS_CFG_IP_MAX 16
/** Runtime configuration loaded from NVS or Kconfig defaults. */
typedef struct {
char wifi_ssid[NVS_CFG_SSID_MAX];
char wifi_password[NVS_CFG_PASS_MAX];
char target_ip[NVS_CFG_IP_MAX];
uint16_t target_port;
uint8_t node_id;
} nvs_config_t;
/**
* Load configuration from NVS, falling back to Kconfig defaults.
*
* Must be called after nvs_flash_init().
*
* @param cfg Output configuration struct.
*/
void nvs_config_load(nvs_config_t *cfg);
#endif /* NVS_CONFIG_H */

View File

@@ -18,7 +18,7 @@ static const char *TAG = "stream_sender";
static int s_sock = -1;
static struct sockaddr_in s_dest_addr;
int stream_sender_init(void)
static int sender_init_internal(const char *ip, uint16_t port)
{
s_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (s_sock < 0) {
@@ -28,19 +28,29 @@ int stream_sender_init(void)
memset(&s_dest_addr, 0, sizeof(s_dest_addr));
s_dest_addr.sin_family = AF_INET;
s_dest_addr.sin_port = htons(CONFIG_CSI_TARGET_PORT);
s_dest_addr.sin_port = htons(port);
if (inet_pton(AF_INET, CONFIG_CSI_TARGET_IP, &s_dest_addr.sin_addr) <= 0) {
ESP_LOGE(TAG, "Invalid target IP: %s", CONFIG_CSI_TARGET_IP);
if (inet_pton(AF_INET, ip, &s_dest_addr.sin_addr) <= 0) {
ESP_LOGE(TAG, "Invalid target IP: %s", ip);
close(s_sock);
s_sock = -1;
return -1;
}
ESP_LOGI(TAG, "UDP sender initialized: %s:%d", CONFIG_CSI_TARGET_IP, CONFIG_CSI_TARGET_PORT);
ESP_LOGI(TAG, "UDP sender initialized: %s:%d", ip, port);
return 0;
}
int stream_sender_init(void)
{
return sender_init_internal(CONFIG_CSI_TARGET_IP, CONFIG_CSI_TARGET_PORT);
}
int stream_sender_init_with(const char *ip, uint16_t port)
{
return sender_init_internal(ip, port);
}
int stream_sender_send(const uint8_t *data, size_t len)
{
if (s_sock < 0) {

View File

@@ -17,6 +17,16 @@
*/
int stream_sender_init(void);
/**
* Initialize the UDP sender with explicit IP and port.
* Used when configuration is loaded from NVS at runtime.
*
* @param ip Aggregator IP address string (e.g. "192.168.1.20").
* @param port Aggregator UDP port.
* @return 0 on success, -1 on error.
*/
int stream_sender_init_with(const char *ip, uint16_t port);
/**
* Send a serialized CSI frame over UDP.
*