Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the '+' wildcard for MQTT rather than '#' #4528

Merged

Conversation

ianmcorvidae
Copy link
Contributor

This means we'll then be subscribing only to topics one nesting level deep, rather than any amount of nesting through the end of the topic, as # does.

Discussed briefly with some of y'all firmware devs but I believe this should be fine and limit what messages are getting sent to firmware a little bit. We're not publishing anything deeper than e.g. msh/2/e/ChannelName/!12345678, meaning msh/2/e/ChannelName/+ will pick that up. Without this change, you could for example set your root topic to msh/2/e/ChannelName, which would then publish messages to msh/2/e/ChannelName/2/e/DifferentChannelName/!abcdef01 and it would go to clients with just msh configured as the prefix and a downlink on the ChannelName channel.

I think that there's another improvement to be made in that we should probably only be subscribing to the json topic if and when the channel name is equal to mqtt, rather than subscribing to it on every channel and then throwing out everything that's not on the mqtt topic. But comparing strings in C++ is a project for a different day, for me :)

@@ -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) {
Copy link
Contributor Author

@ianmcorvidae ianmcorvidae Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: my comment about subscribing only to the right channel for MQTT JSON message-sending, I think this is the conditional it'd need to be added to. In my dynamic language homelands I'd add && channels.getGlobalId(i) == "mqtt" but I think that doesn't work here. Probably easy for one of you, though, haha.

@thebentern thebentern merged commit f99b81a into meshtastic:master Aug 23, 2024
100 checks passed
geeksville pushed a commit to geeksville/Meshtastic-esp32 that referenced this pull request Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants