Add domoticz idx check

Add domoticz idx check while staying backwards compatible (#15677)
This commit is contained in:
Theo Arends 2022-06-02 18:38:06 +02:00
parent 6397f9b4ae
commit e5765a1cd6

View File

@ -202,11 +202,28 @@ bool DomoticzMqttData(void) {
return false; // Process unchanged data 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) { if (XdrvMailbox.data_len < 20) {
return true; // No valid data 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 String domoticz_data = XdrvMailbox.data; // Copy the string into a new buffer that will be modified
JsonParser parser((char*)domoticz_data.c_str()); JsonParser parser((char*)domoticz_data.c_str());
JsonParserObject domoticz = parser.getRootObject(); JsonParserObject domoticz = parser.getRootObject();