Skip to content

Commit

Permalink
Fix getting channel name from MQTT topic
Browse files Browse the repository at this point in the history
  • Loading branch information
GUVWAF committed Feb 8, 2024
1 parent 4c55d5d commit c46d2d1
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/mqtt/MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length)
JSONObject json;
json = json_value->AsObject();

// parse the channel name from the topic string
char *ptr = strtok(topic, "/");
for (int i = 0; i < 3; i++) {
ptr = strtok(NULL, "/");
}
// parse the channel name from the topic string by looking at the last occurrence of "/"
char *ptr = strrchr(topic, '/');
meshtastic_Channel sendChannel = channels.getByName(ptr);
// We allow downlink JSON packets only on a channel named "mqtt"
if (strncasecmp(channels.getGlobalId(sendChannel.index), Channels::mqttChannel, strlen(Channels::mqttChannel)) == 0 &&
Expand Down

0 comments on commit c46d2d1

Please sign in to comment.