From bdbceeb5390c48c270f0cfc97a5b42571aa0d7e5 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Sat, 20 Aug 2022 12:04:44 +0200 Subject: [PATCH] Add HWID to discovery reply --- 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, 15 insertions(+), 6 deletions(-) diff --git a/src/mqtt/hasp_mqtt_esp.cpp b/src/mqtt/hasp_mqtt_esp.cpp index 614908e5..67056db9 100644 --- a/src/mqtt/hasp_mqtt_esp.cpp +++ b/src/mqtt/hasp_mqtt_esp.cpp @@ -99,8 +99,11 @@ int mqtt_send_state(const char* subtopic, const char* payload) int mqtt_send_discovery(const char* payload, size_t len) { - char tmp_topic[20]; - snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR(MQTT_PREFIX "/" MQTT_TOPIC_DISCOVERY)); + 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); 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 d53f35d0..02fd01f6 100644 --- a/src/mqtt/hasp_mqtt_paho_single.cpp +++ b/src/mqtt/hasp_mqtt_paho_single.cpp @@ -231,8 +231,11 @@ int mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload) int mqtt_send_discovery(const char* payload, size_t len) { - char tmp_topic[20]; - snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR(MQTT_PREFIX "/" MQTT_TOPIC_DISCOVERY)); + 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); return mqttPublish(tmp_topic, payload, len, false); } diff --git a/src/mqtt/hasp_mqtt_pubsubclient.cpp b/src/mqtt/hasp_mqtt_pubsubclient.cpp index b038eee3..e9009d1b 100644 --- a/src/mqtt/hasp_mqtt_pubsubclient.cpp +++ b/src/mqtt/hasp_mqtt_pubsubclient.cpp @@ -126,8 +126,11 @@ int mqtt_send_state(const char* subtopic, const char* payload) int mqtt_send_discovery(const char* payload, size_t len) { - char tmp_topic[20]; - snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR(MQTT_PREFIX "/" MQTT_TOPIC_DISCOVERY)); + 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); return mqttPublish(tmp_topic, payload, len, false); }