Files
project-vesper/docs/dev/ota-telemetry-api.md
T
bonaminandClaude Sonnet 4.6 37b65cc15a feat: HAL variant system, OTA improvements, NVS migration scaffold
- Add variants/vesper.hpp and variants/agnus.hpp with HAS_SD_CARD, HAS_RTC,
  HAS_PCF8574, OUTPUT_COUNT_MAX, HW_FAMILY capability flags
- Add agnus-v1 and agnus-mini-v1 PlatformIO environments with -include injection
- Add src/NvsMigration/ scaffold for future NVS schema versioning
- FirmwareHandler: OTA flow improvements and header updates
- OTAManager: FastAPI integration, semver handling improvements
- ConfigManager: refactoring groundwork for NVS-only variant support
- CommunicationRouter: minor fix
- provisioning/nvs_lab_device.csv: fix hw_type to VS, update device id fields
- docs/dev/ota-telemetry-api.md: update API spec

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-15 11:39:11 +02:00

6.7 KiB

OTA Telemetry API — Backend Endpoints Required

The firmware POSTs two events during an OTA update. Both are best-effort — a failure does not abort the update. The device does not retry on failure.


1. Download Event

Trigger: Firmware binary fully written to the staged flash partition, before Update.end() is called. The new firmware is not yet active.

Method: POST Path: /api/ota/events/download

Request Body (JSON)

{
  "device_uid":   "PV000000000000",
  "hw_type":      "vesper",
  "hw_version":   "1.0",
  "from_version": "1.2.3",
  "to_version":   "1.3.0",
  "channel":      "stable"
}
Field Type Description
device_uid string Unique device identifier from NVS
hw_type string Hardware type code (e.g. vesper, vesper-plus, vesper-pro)
hw_version string Hardware revision from NVS (e.g. 1.0)
from_version string Semver of the firmware currently running
to_version string Semver of the firmware that was just downloaded
channel string Update channel (stable, beta, etc.)

Expected Response

Any 2xx status is accepted. Recommended: 204 No Content.


2. Flash Event

Trigger: Update.end() succeeded — the new partition is committed and the device is about to restart. This is the most reliable signal that the update actually landed.

Method: POST Path: /api/ota/events/flash

Request Body (JSON)

{
  "device_uid":   "PV000000000000",
  "hw_type":      "vesper",
  "hw_version":   "1.0",
  "from_version": "1.2.3",
  "to_version":   "1.3.0",
  "channel":      "stable",
  "sha256":       "a3f1...64hexchars...b9e2"
}
Field Type Description
device_uid string Unique device identifier from NVS
hw_type string Hardware type code
hw_version string Hardware revision from NVS
from_version string Semver of the firmware that was running
to_version string Semver of the firmware now committed to flash
channel string Update channel
sha256 string SHA256 of the downloaded binary (from /latest metadata)

Expected Response

Any 2xx status is accepted. Recommended: 204 No Content.


Notes

  • Both requests use the primary server only (servers[0] from the configured list). No retry, no fallback server attempt.
  • Timeout is hardcoded to 5 seconds to avoid blocking the reboot.
  • If WiFi is not connected at the time of the POST, the call is silently skipped.
  • The difference between the two events: download tells you the device received the binary; flash tells you the partition was committed. A device that posts download but never posts flash may have had a verification failure — worth flagging in the backend.

Suggested Backend Behaviour

  • Store both events in a firmware_events table with a type column (download / flash).
  • Index by device_uid + to_version to detect partial failures (download without flash).
  • Use the flash event to drive the "current fleet version" dashboard — it is the ground truth.

Backend Changes Required — Upgrade Chain Resolution

Background

The firmware sends its current version and hardware revision as query parameters on every version check:

GET /api/firmware/{hw_type}/{channel}/latest?hw_version=1.0&current_version=5.7.1

Both parameters are optional. The server must use current_version to resolve upgrade chains and return the correct next hop rather than blindly returning the absolute latest. The device trusts whatever version the server returns and installs it.

hw_version allows the server to filter firmware releases to those compatible with the device's specific hardware revision — useful when a hardware change between revisions requires a different binary.

Example: Device is on 5.7.1. Latest is 7.2.2 but has min_fw_version = 6.0.0.

  • Without chain resolution → server returns 7.2.2 → device cannot install → update silently fails.
  • With chain resolution → server returns 6.0.0 → device installs it → on next boot, server returns 7.2.2 → device installs it.

Changes needed in /api/firmware/{hw_type}/{channel}/latest

  1. Accept hw_version and current_version as optional query parameters (both strings). If absent or unparseable, fall back to current behaviour (return absolute latest, no hw revision filtering).

  2. Resolve the next hop:

    query all published versions for (hw_type, channel), ordered ascending
    find the lowest version V where:
        V > current_version
        AND (V.min_fw_version is null OR current_version >= V.min_fw_version)
    return V
    

    If no such version exists (current is already at latest, or all higher versions have unsatisfied min_fw_version), return 404 or the current version with no update flag.

  3. The response shape does not change — same fields as today. The device doesn't need to know it received an intermediate version rather than the latest.

Example query logic (pseudo-SQL)

SELECT * FROM firmware_releases
WHERE hw_type = :hw_type
  AND channel = :channel
  AND version > :current_version
  AND (min_fw_version IS NULL OR :current_version >= min_fw_version)
  AND (min_hw_version IS NULL OR :hw_version >= min_hw_version)  -- optional hw revision gate
ORDER BY version ASC   -- semver-aware sort
LIMIT 1;

Note: semver ordering must be numeric (1.10.0 > 1.9.0), not lexicographic. Use a semver-aware sort or store major/minor/patch as separate integer columns.

Edge cases to handle

Scenario Expected behaviour
hw_version absent / malformed Ignore param, skip hw revision filtering
current_version absent / malformed Ignore param, return absolute latest (existing behaviour)
Device already at latest Return 404 or 200 with a "no update" indicator — firmware handles both
No version satisfies the chain constraint Return 404 — firmware logs and skips
Multiple intermediate hops needed Server returns only the immediate next hop; device re-checks after each reboot and walks the chain naturally