Skip to content

Commit e6eae8b

Browse files
author
fvanroie
committed
Add retain flag to mqtt_send_state #781
1 parent 73c1539 commit e6eae8b

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

src/mqtt/hasp_mqtt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void mqttStart();
2424
void mqttStop();
2525

2626
// int mqtt_send_object_state(uint8_t pageid, uint8_t btnid, const char* payload);
27-
int mqtt_send_state(const char* subtopic, const char* payload);
27+
int mqtt_send_state(const char* subtopic, const char* payload, bool retain=false);
2828
int mqtt_send_discovery(const char* payload, size_t len);
2929
int mqttPublish(const char* topic, const char* payload, size_t len, bool retain);
3030

src/mqtt/hasp_mqtt_esp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ bool mqtt_send_lwt(bool online)
165165
// return mqttPublish(tmp_topic, payload, false);
166166
// }
167167

168-
int mqtt_send_state(const char* subtopic, const char* payload)
168+
int mqtt_send_state(const char* subtopic, const char* payload, bool retain)
169169
{
170170
String tmp_topic((char*)0);
171171
tmp_topic.reserve(128);
@@ -174,7 +174,7 @@ int mqtt_send_state(const char* subtopic, const char* payload)
174174
// tmp_topic += "/";
175175
tmp_topic += subtopic;
176176

177-
return mqttPublish(tmp_topic.c_str(), payload, false);
177+
return mqttPublish(tmp_topic.c_str(), payload, retain);
178178
}
179179

180180
int mqtt_send_discovery(const char* payload, size_t len)

src/mqtt/hasp_mqtt_paho_async.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,11 @@ bool mqttIsConnected()
284284
return mqttConnected; // MQTTAsync_isConnected(mqtt_client); // <- deadlocking on Linux
285285
}
286286

287-
int mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload)
287+
int mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload, bool retain)
288288
{
289289
char tmp_topic[mqttNodeTopic.length() + 20];
290290
snprintf_P(tmp_topic, sizeof(tmp_topic), ("%s" MQTT_TOPIC_STATE "/%s"), mqttNodeTopic.c_str(), subtopic);
291-
return mqttPublish(tmp_topic, payload, strlen(payload), false);
291+
return mqttPublish(tmp_topic, payload, strlen(payload), retain);
292292
}
293293

294294
int mqtt_send_discovery(const char* payload, size_t len)

src/mqtt/hasp_mqtt_paho_single.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ bool mqttIsConnected()
226226
return MQTTClient_isConnected(mqtt_client);
227227
}
228228

229-
int mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload)
229+
int mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload, bool retain)
230230
{
231231
char tmp_topic[mqttNodeTopic.length() + 20];
232232
snprintf_P(tmp_topic, sizeof(tmp_topic), ("%s" MQTT_TOPIC_STATE "/%s"), mqttNodeTopic.c_str(), subtopic);
233-
return mqttPublish(tmp_topic, payload, strlen(payload), false);
233+
return mqttPublish(tmp_topic, payload, strlen(payload), retain);
234234
}
235235

236236
int mqtt_send_discovery(const char* payload, size_t len)

src/mqtt/hasp_mqtt_pubsubclient.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ bool mqtt_send_lwt(bool online)
117117
// return mqttPublish(tmp_topic, payload, false);
118118
// }
119119

120-
int mqtt_send_state(const char* subtopic, const char* payload)
120+
int mqtt_send_state(const char* subtopic, const char* payload, bool retain)
121121
{
122122
char tmp_topic[strlen(mqttNodeTopic) + strlen(subtopic) + 16];
123123
snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%s" MQTT_TOPIC_STATE "/%s"), mqttNodeTopic, subtopic);
124-
return mqttPublish(tmp_topic, payload, false);
124+
return mqttPublish(tmp_topic, payload, retain);
125125
}
126126

127127
int mqtt_send_discovery(const char* payload, size_t len)

0 commit comments

Comments
 (0)