#pragma once #include #include #include // JSON wire format: {"id":,"data":{"BT":,"ET":}} // Nested document needs two object allocations: // root → 2 keys: "id", "data" // "data" → 2 keys: "BT", "ET" static constexpr size_t TELEMETRY_DOC_SIZE = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(2); static constexpr size_t TELEMETRY_BUF_LEN = 96; // worst case: ~75 chars + null // Serialise a telemetry frame into buf[bufLen]. // Returns number of bytes written (0 on failure / overflow). inline size_t buildTelemetryJson(char* buf, size_t bufLen, int id, float bt, float et) { StaticJsonDocument doc; doc["id"] = id; doc["data"]["BT"] = bt; doc["data"]["ET"] = et; size_t len = serializeJson(doc, buf, bufLen); // serializeJson truncates and null-terminates; len==bufLen-1 means overflow if (len == 0 || len >= bufLen) return 0; return len; }