Use the '+' wildcard for MQTT rather than '#', to subscribe only to topics one nesting level deep (#4528)

This commit is contained in:
Ian McEwen 2024-08-23 05:03:29 -07:00 committed by GitHub
parent 0850ad6c8d
commit f99b81acf7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
}
}