Add HWID to discovery reply

This commit is contained in:
fvanroie 2022-08-20 12:04:44 +02:00
parent 2f307c0a29
commit bdbceeb539
3 changed files with 15 additions and 6 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}