From e5765a1cd6d6cfab078fe3c23df74fdb86ceabd2 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 2 Jun 2022 18:38:06 +0200 Subject: [PATCH] Add domoticz idx check Add domoticz idx check while staying backwards compatible (#15677) --- .../tasmota_xdrv_driver/xdrv_07_domoticz.ino | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_07_domoticz.ino b/tasmota/tasmota_xdrv_driver/xdrv_07_domoticz.ino index b469ef1d5..83f1bfd79 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_07_domoticz.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_07_domoticz.ino @@ -202,11 +202,28 @@ bool DomoticzMqttData(void) { return false; // Process unchanged data } - // topic is domoticz/out so try to analyse + // topic is domoticz/out so check if valid data could be available if (XdrvMailbox.data_len < 20) { return true; // No valid data } + // Quick check if this is mine using topic domoticz/out/{$idx} + if (strlen(XdrvMailbox.topic) > strlen(DOMOTICZ_OUT_TOPIC)) { + char* topic_index = &XdrvMailbox.topic[strlen(DOMOTICZ_OUT_TOPIC) +1]; + uint32_t idx = atoi(topic_index); + uint8_t maxdev = (TasmotaGlobal.devices_present > MAX_DOMOTICZ_IDX) ? MAX_DOMOTICZ_IDX : TasmotaGlobal.devices_present; + bool not_found = true; + for (uint32_t i = 0; i < maxdev; i++) { + if (idx == Settings->domoticz_relay_idx[i]) { + not_found = false; + break; + } + } + if (not_found) { + return true; // Idx not mine + } + } + String domoticz_data = XdrvMailbox.data; // Copy the string into a new buffer that will be modified JsonParser parser((char*)domoticz_data.c_str()); JsonParserObject domoticz = parser.getRootObject();