Skip to content

Commit

Permalink
Use the '+' wildcard for MQTT rather than '#', to subscribe only to t…
Browse files Browse the repository at this point in the history
…opics one nesting level deep (meshtastic#4528)
  • Loading branch information
ianmcorvidae authored and geeksville committed Aug 28, 2024
1 parent de41a05 commit fe9a80a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/mqtt/MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
}
}

0 comments on commit fe9a80a

Please sign in to comment.