feat(firmware): ESP32-P4 sensor node — Workstream I core skeleton
New firmware/esp32p4-sensor-node/ ESP-IDF (C, FreeRTOS) project skeleton per docs/superpowers/specs/2026-07-23-esp32-sensor-node-design.md's Workstream I: - Wi-Fi station-mode connect with exponential-backoff reconnect (wifi_manager.c), credentials from a gitignored main/device_config.h the seeker fills in (template: device_config.h.example). - Telemetry HTTP client (telemetry_client.c) POSTing the spec's exact contract shape to /api/device/telemetry with a Bearer token, via esp_http_client + cJSON. - BME280 I2C driver (bme280.c) with Bosch's public double-precision compensation formulas, using ESP-IDF's newer driver/i2c_master.h API. - LD2410 mmWave presence driver (ld2410.c) over UART, chosen over a plain PIR for its distance/motion data richness — its frame-offset parsing is flagged as the least-certain code in the firmware. - sensor_driver_t registry (sensor_driver.h, sensor_registry.c) so new sensors are a new driver file + one array line, no main-loop changes. - README.md: build steps, manual-config walkthrough, wiring/pinouts, and an explicit "what's verified vs. not" section plus a real hardware caveat (ESP32-P4 has no integrated Wi-Fi radio). UNVERIFIED AGAINST REAL HARDWARE per the spec's honesty-policy note — no ESP-IDF toolchain or physical boards available in this environment. Syntax-checked with gcc against hand-written ESP-IDF API stubs (not committed) as a best-effort substitute for a real idf.py build. Workstream J (RTL-SDR experimental module) is explicitly out of scope here; firmware/esp32p4-sensor-node/components/ is left in place for it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
51
firmware/esp32p4-sensor-node/main/app_main.c
Normal file
51
firmware/esp32p4-sensor-node/main/app_main.c
Normal file
@@ -0,0 +1,51 @@
|
||||
// Quantumancy ESP32-P4 Sensor Node — entry point.
|
||||
//
|
||||
// UNVERIFIED AGAINST REAL HARDWARE. Nobody working on this workstream has a
|
||||
// physical ESP32-P4 (or the BME280 / LD2410 modules) to flash and test
|
||||
// against. This firmware is real, structurally-sound ESP-IDF C, reasoned
|
||||
// about carefully against ESP-IDF's documented APIs and the public
|
||||
// datasheets/protocol docs for each sensor -- but "compiles and reads
|
||||
// correctly" is where the verification stops. See README.md's "What's
|
||||
// verified vs. not" section before treating any of this as field-tested.
|
||||
//
|
||||
// Boot sequence: bring up Wi-Fi station mode (device_config.h credentials),
|
||||
// wait (briefly, non-fatally) for an initial connection, initialize every
|
||||
// registered sensor driver, then hand off to the telemetry task, which
|
||||
// periodically samples the sensor registry and POSTs the results to the
|
||||
// backend. Wi-Fi reconnection and per-cycle "are we online" checks happen
|
||||
// independently after this, so a boot-time Wi-Fi hiccup doesn't wedge the
|
||||
// device -- it just starts reporting once the connection comes up.
|
||||
|
||||
#include "wifi_manager.h"
|
||||
#include "sensor_registry.h"
|
||||
#include "telemetry_client.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
static const char *TAG = "app_main";
|
||||
|
||||
// How long to wait at boot for the first Wi-Fi connection before giving up
|
||||
// on blocking and handing off to the telemetry task anyway (which will
|
||||
// simply skip cycles until wifi_manager's own retry logic connects).
|
||||
#define BOOT_WIFI_WAIT_MS 20000
|
||||
|
||||
void app_main(void) {
|
||||
ESP_LOGI(TAG, "Quantumancy sensor node starting");
|
||||
|
||||
ESP_ERROR_CHECK(wifi_manager_start());
|
||||
|
||||
esp_err_t err = wifi_manager_wait_connected(pdMS_TO_TICKS(BOOT_WIFI_WAIT_MS));
|
||||
if (err == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Wi-Fi connected at boot");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Wi-Fi not connected within %d ms at boot -- continuing anyway, "
|
||||
"wifi_manager will keep retrying in the background", BOOT_WIFI_WAIT_MS);
|
||||
}
|
||||
|
||||
sensor_registry_init_all();
|
||||
telemetry_client_start_task();
|
||||
|
||||
ESP_LOGI(TAG, "startup complete, telemetry task running");
|
||||
}
|
||||
Reference in New Issue
Block a user