From 2c625f6ba1dd18f4102c45d7c0f3fb573378daa8 Mon Sep 17 00:00:00 2001 From: Andre K Date: Sun, 15 Oct 2023 08:41:40 -0300 Subject: [PATCH] fix: channel routing for decoded MQTT packets (#2892) Co-authored-by: Ben Meadors --- src/mqtt/MQTT.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index f369f873f..cbaba45d6 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -133,10 +133,16 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length) if (strcmp(e.gateway_id, owner.id) == 0) LOG_INFO("Ignoring downlink message we originally sent.\n"); else { - if (e.packet) { + // Find channel by channel_id and check downlink_enabled + meshtastic_Channel ch = channels.getByName(e.channel_id); + if (strcmp(e.channel_id, channels.getGlobalId(ch.index)) == 0 && e.packet && ch.settings.downlink_enabled) { LOG_INFO("Received MQTT topic %s, len=%u\n", topic, length); meshtastic_MeshPacket *p = packetPool.allocCopy(*e.packet); + if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { + p->channel = ch.index; + } + // ignore messages sent by us or if we don't have the channel key if (router && p->from != nodeDB.getNodeNum() && perhapsDecode(p)) router->enqueueReceivedMessage(p);