Fix subscribe rule handling

This commit is contained in:
Theo Arends 2024-01-23 12:32:12 +01:00
parent 669fc1ecfa
commit a9a3f5638c
1 changed files with 8 additions and 6 deletions

View File

@ -1175,15 +1175,17 @@ bool RulesMqttData(void) {
return false; // Process unchanged data return false; // Process unchanged data
} }
bool serviced = false; bool serviced = false;
String buData = XdrvMailbox.data; // Could be very long SENSOR message String buData = XdrvMailbox.data; // Distroyed by JsonParser. Could be very long SENSOR message
char ctopic[strlen(XdrvMailbox.topic)+1];
strcpy(ctopic, XdrvMailbox.topic); // Distroyed by result of following iteration
// Looking for matched topic // Looking for matched topic
for (auto &event_item : subscriptions) { for (auto &event_item : subscriptions) {
char stopic[strlen(event_item.topic)+2]; char etopic[strlen(event_item.topic)+2];
strcpy(stopic, event_item.topic); strcpy(etopic, event_item.topic);
strcat(stopic, "/"); strcat(etopic, "/");
if ((strcmp(XdrvMailbox.topic, event_item.topic) == 0) || // Equal if ((strcmp(ctopic, event_item.topic) == 0) || // Equal
(strncmp(XdrvMailbox.topic, stopic, strlen(XdrvMailbox.topic)) == 0)) { // StartsWith (strncmp(ctopic, etopic, strlen(etopic)) == 0)) { // StartsWith
// This topic is subscribed by us, so serve it // This topic is subscribed by us, so serve it
serviced = true; serviced = true;