mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-21 10:16:34 +00:00
Add retain flag to mqtt_send_state #781
This commit is contained in:
parent
73c1539fda
commit
e6eae8b391
@ -24,7 +24,7 @@ void mqttStart();
|
||||
void mqttStop();
|
||||
|
||||
// int mqtt_send_object_state(uint8_t pageid, uint8_t btnid, const char* payload);
|
||||
int mqtt_send_state(const char* subtopic, const char* payload);
|
||||
int mqtt_send_state(const char* subtopic, const char* payload, bool retain=false);
|
||||
int mqtt_send_discovery(const char* payload, size_t len);
|
||||
int mqttPublish(const char* topic, const char* payload, size_t len, bool retain);
|
||||
|
||||
|
@ -165,7 +165,7 @@ bool mqtt_send_lwt(bool online)
|
||||
// return mqttPublish(tmp_topic, payload, false);
|
||||
// }
|
||||
|
||||
int mqtt_send_state(const char* subtopic, const char* payload)
|
||||
int mqtt_send_state(const char* subtopic, const char* payload, bool retain)
|
||||
{
|
||||
String tmp_topic((char*)0);
|
||||
tmp_topic.reserve(128);
|
||||
@ -174,7 +174,7 @@ int mqtt_send_state(const char* subtopic, const char* payload)
|
||||
// tmp_topic += "/";
|
||||
tmp_topic += subtopic;
|
||||
|
||||
return mqttPublish(tmp_topic.c_str(), payload, false);
|
||||
return mqttPublish(tmp_topic.c_str(), payload, retain);
|
||||
}
|
||||
|
||||
int mqtt_send_discovery(const char* payload, size_t len)
|
||||
|
@ -284,11 +284,11 @@ bool mqttIsConnected()
|
||||
return mqttConnected; // MQTTAsync_isConnected(mqtt_client); // <- deadlocking on Linux
|
||||
}
|
||||
|
||||
int mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload)
|
||||
int mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload, bool retain)
|
||||
{
|
||||
char tmp_topic[mqttNodeTopic.length() + 20];
|
||||
snprintf_P(tmp_topic, sizeof(tmp_topic), ("%s" MQTT_TOPIC_STATE "/%s"), mqttNodeTopic.c_str(), subtopic);
|
||||
return mqttPublish(tmp_topic, payload, strlen(payload), false);
|
||||
return mqttPublish(tmp_topic, payload, strlen(payload), retain);
|
||||
}
|
||||
|
||||
int mqtt_send_discovery(const char* payload, size_t len)
|
||||
|
@ -226,11 +226,11 @@ bool mqttIsConnected()
|
||||
return MQTTClient_isConnected(mqtt_client);
|
||||
}
|
||||
|
||||
int mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload)
|
||||
int mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload, bool retain)
|
||||
{
|
||||
char tmp_topic[mqttNodeTopic.length() + 20];
|
||||
snprintf_P(tmp_topic, sizeof(tmp_topic), ("%s" MQTT_TOPIC_STATE "/%s"), mqttNodeTopic.c_str(), subtopic);
|
||||
return mqttPublish(tmp_topic, payload, strlen(payload), false);
|
||||
return mqttPublish(tmp_topic, payload, strlen(payload), retain);
|
||||
}
|
||||
|
||||
int mqtt_send_discovery(const char* payload, size_t len)
|
||||
|
@ -117,11 +117,11 @@ bool mqtt_send_lwt(bool online)
|
||||
// return mqttPublish(tmp_topic, payload, false);
|
||||
// }
|
||||
|
||||
int mqtt_send_state(const char* subtopic, const char* payload)
|
||||
int mqtt_send_state(const char* subtopic, const char* payload, bool retain)
|
||||
{
|
||||
char tmp_topic[strlen(mqttNodeTopic) + strlen(subtopic) + 16];
|
||||
snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%s" MQTT_TOPIC_STATE "/%s"), mqttNodeTopic, subtopic);
|
||||
return mqttPublish(tmp_topic, payload, false);
|
||||
return mqttPublish(tmp_topic, payload, retain);
|
||||
}
|
||||
|
||||
int mqtt_send_discovery(const char* payload, size_t len)
|
||||
|
Loading…
x
Reference in New Issue
Block a user