From f99b81acf771279cfeea09bc350db979d6c89592 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Fri, 23 Aug 2024 05:03:29 -0700 Subject: [PATCH] Use the '+' wildcard for MQTT rather than '#', to subscribe only to topics one nesting level deep (#4528) --- src/mqtt/MQTT.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 22f68bac8..2f7e82e3d 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -376,12 +376,12 @@ void MQTT::sendSubscriptions() const auto &ch = channels.getByIndex(i); if (ch.settings.downlink_enabled) { hasDownlink = true; - std::string topic = cryptTopic + channels.getGlobalId(i) + "/#"; + std::string topic = cryptTopic + channels.getGlobalId(i) + "/+"; LOG_INFO("Subscribing to %s\n", topic.c_str()); pubSub.subscribe(topic.c_str(), 1); // FIXME, is QOS 1 right? #ifndef ARCH_NRF52 // JSON is not supported on nRF52, see issue #2804 if (moduleConfig.mqtt.json_enabled == true) { - std::string topicDecoded = jsonTopic + channels.getGlobalId(i) + "/#"; + std::string topicDecoded = jsonTopic + channels.getGlobalId(i) + "/+"; LOG_INFO("Subscribing to %s\n", topicDecoded.c_str()); pubSub.subscribe(topicDecoded.c_str(), 1); // FIXME, is QOS 1 right? } @@ -390,7 +390,7 @@ void MQTT::sendSubscriptions() } #if !MESHTASTIC_EXCLUDE_PKI if (hasDownlink) { - std::string topic = cryptTopic + "PKI/#"; + std::string topic = cryptTopic + "PKI/+"; LOG_INFO("Subscribing to %s\n", topic.c_str()); pubSub.subscribe(topic.c_str(), 1); } @@ -674,4 +674,4 @@ bool MQTT::isValidJsonEnvelope(JSONObject &json) (json["from"]->AsNumber() == nodeDB->getNodeNum()) && // only accept message if the "from" is us (json.find("type") != json.end()) && json["type"]->IsString() && // should specify a type (json.find("payload") != json.end()); // should have a payload -} \ No newline at end of file +}