From 8ff5dacc3c53ee4d3c1e29bb358615dd614a6906 Mon Sep 17 00:00:00 2001 From: arduinoGP <115203453+arduionoGP@users.noreply.github.com> Date: Thu, 1 Dec 2022 15:44:47 -0500 Subject: [PATCH] Update MQTT.cpp case Portnum_POSITION_APP adjusted so the various options allways get encoded into JSON as long as lat and long are present. There are circumstances where timestamp, time, or altitude might be missing and this causes silent failures of JSON encoding.. --- src/mqtt/MQTT.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 05f662444..8af009bad 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -346,11 +346,11 @@ std::string MQTT::downstreamPacketToJson(MeshPacket *mp) memset(&scratch, 0, sizeof(scratch)); if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &Position_msg, &scratch)) { decoded = &scratch; - msgPayload["time"] = new JSONValue((int)decoded->time); - msgPayload["timestamp"] = new JSONValue((int)decoded->timestamp); + if((int)decoded->time){msgPayload["time"] = new JSONValue((int)decoded->time);} + if ((int)decoded->timestamp){msgPayload["timestamp"] = new JSONValue((int)decoded->timestamp);} msgPayload["latitude_i"] = new JSONValue((int)decoded->latitude_i); msgPayload["longitude_i"] = new JSONValue((int)decoded->longitude_i); - msgPayload["altitude"] = new JSONValue((int)decoded->altitude); + if((int)decoded->altitude){msgPayload["altitude"] = new JSONValue((int)decoded->altitude);} jsonObj["payload"] = new JSONValue(msgPayload); } else { DEBUG_MSG("Error decoding protobuf for position message!\n");