From a9a3f5638ca2089948c95e6108f0961537fb9922 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 23 Jan 2024 12:32:12 +0100 Subject: [PATCH] Fix subscribe rule handling --- tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino b/tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino index 0d0df2120..1450ed821 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino @@ -1175,15 +1175,17 @@ bool RulesMqttData(void) { return false; // Process unchanged data } 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 for (auto &event_item : subscriptions) { - char stopic[strlen(event_item.topic)+2]; - strcpy(stopic, event_item.topic); - strcat(stopic, "/"); - if ((strcmp(XdrvMailbox.topic, event_item.topic) == 0) || // Equal - (strncmp(XdrvMailbox.topic, stopic, strlen(XdrvMailbox.topic)) == 0)) { // StartsWith + char etopic[strlen(event_item.topic)+2]; + strcpy(etopic, event_item.topic); + strcat(etopic, "/"); + if ((strcmp(ctopic, event_item.topic) == 0) || // Equal + (strncmp(ctopic, etopic, strlen(etopic)) == 0)) { // StartsWith // This topic is subscribed by us, so serve it serviced = true;