Update discovery reply topic

This commit is contained in:
fvanroie 2022-08-20 22:34:50 +02:00
parent 9a17e70daf
commit 4852b6f4c4
3 changed files with 6 additions and 15 deletions

View File

@ -99,11 +99,8 @@ int mqtt_send_state(const char* subtopic, const char* payload)
int mqtt_send_discovery(const char* payload, size_t len) int mqtt_send_discovery(const char* payload, size_t len)
{ {
char tmp_topic[64]; char tmp_topic[128];
size_t size = sizeof(tmp_topic); snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR(MQTT_PREFIX "/" MQTT_TOPIC_DISCOVERY "/%s"),haspDevice.get_hardware_id());
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); return mqttPublish(tmp_topic, payload, len, false);
} }

View File

@ -231,11 +231,8 @@ int mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload)
int mqtt_send_discovery(const char* payload, size_t len) int mqtt_send_discovery(const char* payload, size_t len)
{ {
char tmp_topic[64]; char tmp_topic[128];
size_t size = sizeof(tmp_topic); snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR(MQTT_PREFIX "/" MQTT_TOPIC_DISCOVERY "/%s"),haspDevice.get_hardware_id());
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); return mqttPublish(tmp_topic, payload, len, false);
} }

View File

@ -126,11 +126,8 @@ int mqtt_send_state(const char* subtopic, const char* payload)
int mqtt_send_discovery(const char* payload, size_t len) int mqtt_send_discovery(const char* payload, size_t len)
{ {
char tmp_topic[64]; char tmp_topic[128];
size_t size = sizeof(tmp_topic); snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR(MQTT_PREFIX "/" MQTT_TOPIC_DISCOVERY "/%s"),haspDevice.get_hardware_id());
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); return mqttPublish(tmp_topic, payload, len, false);
} }