// 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 #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 "/api/device/telemetry" with // `Authorization: Bearer ` 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