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>
37 lines
1.3 KiB
C
37 lines
1.3 KiB
C
// HTTP client for POSTing sensor readings to the Quantumancy backend's
|
|
// `POST /api/device/telemetry` endpoint (see the design spec's "Contract"
|
|
// section: docs/superpowers/specs/2026-07-23-esp32-sensor-node-design.md).
|
|
//
|
|
// UNVERIFIED AGAINST REAL HARDWARE — see README.md.
|
|
|
|
#pragma once
|
|
|
|
#include <stddef.h>
|
|
#include "esp_err.h"
|
|
#include "sensor_driver.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
// Builds the request body:
|
|
// {"readings": [{"sensor_type": str, "value": number, "unit": str,
|
|
// "metadata": {}}, ...]}
|
|
// and POSTs it to "<DEVICE_BACKEND_BASE_URL>/api/device/telemetry" with
|
|
// `Authorization: Bearer <DEVICE_PAIRING_TOKEN>` and
|
|
// `Content-Type: application/json`. Takes ownership of any non-NULL
|
|
// `metadata` cJSON pointers in `readings` — they are freed as part of
|
|
// building/serializing the body regardless of whether the POST succeeds.
|
|
// No-ops (returns ESP_OK) if `count` is 0.
|
|
esp_err_t telemetry_client_post_readings(const sensor_reading_t *readings, size_t count);
|
|
|
|
// Starts the FreeRTOS task that, on a DEVICE_REPORT_INTERVAL_SEC cadence,
|
|
// collects a fresh batch of readings from the sensor registry and POSTs
|
|
// them via telemetry_client_post_readings(). Call once from app_main()
|
|
// after wifi_manager_start() and sensor_registry_init_all().
|
|
void telemetry_client_start_task(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|