Skip to content

Commit

Permalink
Merge pull request wled#1307 from herm/mqtt_topic
Browse files Browse the repository at this point in the history
Fix MQTT topic parsing.
  • Loading branch information
Aircoookie authored Nov 1, 2020
2 parents 2d12bc0 + b694bcf commit e8bd114
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions wled00/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,34 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
}
DEBUG_PRINTLN(payload);

//no need to check the topic because we only get topics we are subscribed to
size_t topicPrefixLen = strlen(mqttDeviceTopic);
if (strncmp(topic, mqttDeviceTopic, topicPrefixLen) == 0) {
topic += topicPrefixLen;
} else {
size_t topic_prefix_len = strlen(mqttGroupTopic);
if (strncmp(topic, mqttGroupTopic, topicPrefixLen) == 0) {
topic += topicPrefixLen;
} else {
// Topic not used here. Probably a usermod subscribed to this topic.
return;
}
}

//Prefix is stripped from the topic at this point

if (strstr(topic, "/col"))
if (strcmp(topic, "/col") == 0)
{
colorFromDecOrHexString(col, (char*)payload);
colorUpdated(NOTIFIER_CALL_MODE_DIRECT_CHANGE);
} else if (strstr(topic, "/api"))
} else if (strcmp(topic, "/api") == 0)
{
String apireq = "win&";
apireq += (char*)payload;
handleSet(nullptr, apireq);
} else parseMQTTBriPayload(payload);
} else if (strcmp(topic, "") == 0)
{
parseMQTTBriPayload(payload);
}
}


Expand Down

0 comments on commit e8bd114

Please sign in to comment.