Context
The hello payload already shipped a malformed-JSON bug once (missing quote: "message_type":hello") — it compiled fine and would only have surfaced at the host. Nothing today verifies that the JSON the firmware emits is actually JSON.
The builders are currently untestable by structure:
buildTelemetryJson() and appendTempArray() are static inside main.cpp
- the hello payload
snprintf is inline in TelemetrySender::hello()
Scope
Extract the payload builders into their own compilation unit (e.g. TelemetryJson.h/.cpp) so tests can call them, then add Unity tests that feed the output back through ArduinoJson's parser.
Test cases
- Hello payload parses as JSON;
message_type == "hello", mac matches input
- Telemetry JSON parses end to end
NAN and the DS18B20 error sentinel 85.0 render as null in temperature arrays
failoverDetails containing quotes / control characters is escaped and does not break the document
- Undersized output buffer truncates safely instead of overflowing
Acceptance criteria
- Builders live outside
main.cpp and firmware behavior is unchanged.
- Every emitted payload shape has a parse-it-back test.
- The historical missing-quote bug class cannot recur silently.
Context
The hello payload already shipped a malformed-JSON bug once (missing quote:
"message_type":hello") — it compiled fine and would only have surfaced at the host. Nothing today verifies that the JSON the firmware emits is actually JSON.The builders are currently untestable by structure:
buildTelemetryJson()andappendTempArray()arestaticinsidemain.cppsnprintfis inline inTelemetrySender::hello()Scope
Extract the payload builders into their own compilation unit (e.g.
TelemetryJson.h/.cpp) so tests can call them, then add Unity tests that feed the output back through ArduinoJson's parser.Test cases
message_type == "hello",macmatches inputNANand the DS18B20 error sentinel85.0render asnullin temperature arraysfailoverDetailscontaining quotes / control characters is escaped and does not break the documentAcceptance criteria
main.cppand firmware behavior is unchanged.