Skip to content

Extract JSON payload builders and add format regression tests #15

Description

@TalkingJupiter

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions