diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 8af009bad..96135bc34 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -61,7 +61,27 @@ void MQTT::onPublish(char *topic, byte *payload, unsigned int length) } else { DEBUG_MSG("JSON Ignoring downlink message we originally sent.\n"); } - } else { + } else if ((json.find("sender") != json.end()) && (json.find("payload") != json.end()) && (json.find("type") != json.end()) && json["type"]->IsString() && (json["type"]->AsString().compare("sendposition") == 0)) { + //invent the "sendposition" type for a valid envelope + if (json["payload"]->IsObject() && json["type"]->IsString() && (json["sender"]->AsString().compare(owner.id) != 0)) { + JSONObject posit; + posit=json["payload"]->AsObject(); //get nested JSON Position + Position pos =Position_init_default; + pos.latitude_i=posit["latitude_i"]->AsNumber(); + pos.longitude_i=posit["longitude_i"]->AsNumber(); + pos.altitude=posit["altitude"]->AsNumber(); + pos.time=posit["time"]->AsNumber(); + + // construct protobuf data packet using POSITION, send it to the mesh + MeshPacket *p = router->allocForSending(); + p->decoded.portnum = PortNum_POSITION_APP; + p->decoded.payload.size=pb_encode_to_bytes(p->decoded.payload.bytes,sizeof(p->decoded.payload.bytes),Position_fields, &pos); //make the Data protobuf from position + service.sendToMesh(p, RX_SRC_LOCAL); + + } else { + DEBUG_MSG("JSON Ignoring downlink message we originally sent.\n"); + } + } else{ DEBUG_MSG("JSON Received payload on MQTT but not a valid envelope\n"); } } else {