From 7d87cbabcd41141f702feb0fa7a43a1ae78c5c41 Mon Sep 17 00:00:00 2001 From: GUVWAF Date: Thu, 8 Feb 2024 20:29:23 +0100 Subject: [PATCH] Allow specifying channel index in JSON field "channel" for downlink Still requires JSON message to be published to channel named "mqtt" --- src/mqtt/MQTT.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 300a87c245..f2fb094dee 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -67,7 +67,9 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length) // construct protobuf data packet using TEXT_MESSAGE, send it to the mesh meshtastic_MeshPacket *p = router->allocForSending(); p->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP; - p->channel = sendChannel.index; + if (json.find("channel") != json.end() && json["channel"]->IsNumber() && + (json["channel"]->AsNumber() < channels.getNumChannels())) + p->channel = json["channel"]->AsNumber(); if (json.find("to") != json.end() && json["to"]->IsNumber()) p->to = json["to"]->AsNumber(); if (jsonPayloadStr.length() <= sizeof(p->decoded.payload.bytes)) { @@ -95,7 +97,9 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length) // construct protobuf data packet using POSITION, send it to the mesh meshtastic_MeshPacket *p = router->allocForSending(); p->decoded.portnum = meshtastic_PortNum_POSITION_APP; - p->channel = sendChannel.index; + if (json.find("channel") != json.end() && json["channel"]->IsNumber() && + (json["channel"]->AsNumber() < channels.getNumChannels())) + p->channel = json["channel"]->AsNumber(); if (json.find("to") != json.end() && json["to"]->IsNumber()) p->to = json["to"]->AsNumber(); p->decoded.payload.size =