From 4bb7c5502db075794eecdd967db17482515b007c Mon Sep 17 00:00:00 2001 From: DigiH Date: Mon, 17 Jun 2024 20:37:39 +0200 Subject: [PATCH] [DISC] reorder UVI for correct auto-discovery (#1968) To avoid auto-discovery issues due to substring comparison at https://github.com/1technophile/OpenMQTTGateway/blob/development/main/ZgatewayRTL_433.ino#L128 strcmp instead of substring only strstr --- main/ZgatewayRTL_433.ino | 7 ++++++- main/config_RF.h | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/main/ZgatewayRTL_433.ino b/main/ZgatewayRTL_433.ino index ac4afa0..ae7d72c 100644 --- a/main/ZgatewayRTL_433.ino +++ b/main/ZgatewayRTL_433.ino @@ -125,7 +125,12 @@ void launchRTL_433Discovery(bool overrideDiscovery) { if (overrideDiscovery || !isDiscovered(pdevice)) { size_t numRows = sizeof(parameters) / sizeof(parameters[0]); for (int i = 0; i < numRows; i++) { - if (strstr(pdevice->uniqueId, parameters[i][0]) != 0) { + char deviceKeyParameter[25]; + memcpy(deviceKeyParameter, &pdevice->uniqueId[strlen(pdevice->uniqueId) - strlen(parameters[i][0])], strlen(parameters[i][0])); + deviceKeyParameter[strlen(parameters[i][0])] = '\0'; + Log.trace(F("deviceKeyParameter: %s" CR), deviceKeyParameter); + + if (strcmp(deviceKeyParameter, parameters[i][0]) == 0) { // Remove the key from the unique id to extract the device id String idWoKey = pdevice->uniqueId; idWoKey.remove(idWoKey.length() - (strlen(parameters[i][0]) + 1)); diff --git a/main/config_RF.h b/main/config_RF.h index 6dea2f1..e531937 100644 --- a/main/config_RF.h +++ b/main/config_RF.h @@ -82,7 +82,7 @@ struct RTL_433device { bool isDisc; }; -const char parameters[53][4][24] = { +const char parameters[51][4][24] = { // RTL_433 key, name, unit, device_class {"alarm", "Alarm", "", ""}, {"battery_mV", "Battery Voltage", "mV", "voltage"},