From 4852b6f4c4e683fd9b447836a19ae690284e7817 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Sat, 20 Aug 2022 22:34:50 +0200 Subject: [PATCH] Update discovery reply topic --- src/mqtt/hasp_mqtt_esp.cpp | 7 ++----- src/mqtt/hasp_mqtt_paho_single.cpp | 7 ++----- src/mqtt/hasp_mqtt_pubsubclient.cpp | 7 ++----- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/mqtt/hasp_mqtt_esp.cpp b/src/mqtt/hasp_mqtt_esp.cpp index 67056db9..b1d95e90 100644 --- a/src/mqtt/hasp_mqtt_esp.cpp +++ b/src/mqtt/hasp_mqtt_esp.cpp @@ -99,11 +99,8 @@ int mqtt_send_state(const char* subtopic, const char* payload) int mqtt_send_discovery(const char* payload, size_t len) { - char tmp_topic[64]; - size_t size = sizeof(tmp_topic); - snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR(MQTT_PREFIX "/" MQTT_TOPIC_DISCOVERY "/")); - size -= strlen(tmp_topic); - strlcat(tmp_topic, haspDevice.get_hardware_id(), size); + char tmp_topic[128]; + snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR(MQTT_PREFIX "/" MQTT_TOPIC_DISCOVERY "/%s"),haspDevice.get_hardware_id()); return mqttPublish(tmp_topic, payload, len, false); } diff --git a/src/mqtt/hasp_mqtt_paho_single.cpp b/src/mqtt/hasp_mqtt_paho_single.cpp index 02fd01f6..1882cb83 100644 --- a/src/mqtt/hasp_mqtt_paho_single.cpp +++ b/src/mqtt/hasp_mqtt_paho_single.cpp @@ -231,11 +231,8 @@ int mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload) int mqtt_send_discovery(const char* payload, size_t len) { - char tmp_topic[64]; - size_t size = sizeof(tmp_topic); - snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR(MQTT_PREFIX "/" MQTT_TOPIC_DISCOVERY "/")); - size -= strlen(tmp_topic); - strlcat(tmp_topic, haspDevice.get_hardware_id(), size); + char tmp_topic[128]; + snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR(MQTT_PREFIX "/" MQTT_TOPIC_DISCOVERY "/%s"),haspDevice.get_hardware_id()); return mqttPublish(tmp_topic, payload, len, false); } diff --git a/src/mqtt/hasp_mqtt_pubsubclient.cpp b/src/mqtt/hasp_mqtt_pubsubclient.cpp index e9009d1b..a2b8ed2d 100644 --- a/src/mqtt/hasp_mqtt_pubsubclient.cpp +++ b/src/mqtt/hasp_mqtt_pubsubclient.cpp @@ -126,11 +126,8 @@ int mqtt_send_state(const char* subtopic, const char* payload) int mqtt_send_discovery(const char* payload, size_t len) { - char tmp_topic[64]; - size_t size = sizeof(tmp_topic); - snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR(MQTT_PREFIX "/" MQTT_TOPIC_DISCOVERY "/")); - size -= strlen(tmp_topic); - strlcat(tmp_topic, haspDevice.get_hardware_id(), size); + char tmp_topic[128]; + snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR(MQTT_PREFIX "/" MQTT_TOPIC_DISCOVERY "/%s"),haspDevice.get_hardware_id()); return mqttPublish(tmp_topic, payload, len, false); }