From 44ef6c063c4f9195f9300c99adecbcb5f2f16c7a Mon Sep 17 00:00:00 2001 From: fredlcore Date: Sat, 28 Dec 2024 13:55:16 +0800 Subject: [PATCH] Remove dot from MQTT topic as it confuses HA --- BSB_LAN/BSB_LAN.ino | 17 +++++++++++++---- BSB_LAN/include/mqtt_handler.h | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/BSB_LAN/BSB_LAN.ino b/BSB_LAN/BSB_LAN.ino index ca53c3e9..e96ca508 100644 --- a/BSB_LAN/BSB_LAN.ino +++ b/BSB_LAN/BSB_LAN.ino @@ -1176,9 +1176,9 @@ float get_next_prognr(float currentProgNr){ } else { if(recognizeVirtualFunctionGroup(currentProgNr + 1)){ #if defined(__SAM3X8E__) - double intpart; + double intpart; #else - float intpart; + float intpart; #endif modf(currentProgNr, &intpart); nextprognr = intpart + 1; @@ -1640,6 +1640,15 @@ void remove_char(char* str, char c) { *pw = '\0'; } +void replace_char(char *str, char find, char replace) { + while (*str) { // Traverse the string until null terminator + if (*str == find) { + *str = replace; // Replace the character + } + str++; + } +} + void resetDurations() { brenner_duration=0; brenner_count=0; @@ -3708,7 +3717,7 @@ void queryVirtualPrognr(float line, int table_line) { } case 4: { size_t log_sensor = roundf(line - (float)BSP_ONEWIRE); - if (One_Wire_Pin >= 0 && numSensors) { + if (oneWire && numSensors) { switch (((int)roundf((line - (float)BSP_ONEWIRE) * 10)) % 10) { case 0: //print sensor ID DeviceAddress device_address; @@ -6819,7 +6828,7 @@ next_parameter: } { - if (One_Wire_Pin >= 0) { + if (oneWire) { unsigned long tempTime = millis() / ONE_WIRE_REQUESTS_PERIOD; if (tempTime != lastOneWireRequestTime) { sensors->requestTemperatures(); //call it outside of here for more faster answers diff --git a/BSB_LAN/include/mqtt_handler.h b/BSB_LAN/include/mqtt_handler.h index baeabeca..c069ac95 100644 --- a/BSB_LAN/include/mqtt_handler.h +++ b/BSB_LAN/include/mqtt_handler.h @@ -523,6 +523,7 @@ boolean mqtt_send_discovery(boolean create=true) { appendStringBuffer(&sb_topic, "BSB-LAN/%g-%d-%d-%d/config", line, active_cmdtbl[i].dev_fam, active_cmdtbl[i].dev_var, my_dev_serial); + replace_char(MQTTTopic, '.', '-'); if (!create) { MQTTPayload[0] = '\0'; // If remove flag is set, send empty message to instruct auto discovery to remove the entry }