Skip to content

Commit 3eac3e3

Browse files
committed
added publish functions
1 parent 0a07062 commit 3eac3e3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/MqttClient.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,28 @@ int MqttClient::endMessage()
259259
return 1;
260260
}
261261

262+
int MqttClient::publish(const char* topic, const char* payload, bool retain, uint8_t qos, bool dup) {
263+
int ret = beginMessage(topic, strlen_P(payload), retain, qos, dup);
264+
if (!ret) {
265+
return ret;
266+
}
267+
print(payload);
268+
ret = endMessage();
269+
return ret;
270+
}
271+
272+
int MqttClient::publish(const String& topic, const char* payload, bool retain, uint8_t qos, bool dup) {
273+
publish(topic.c_str(), payload, retain, qos, dup);
274+
}
275+
276+
int MqttClient::publish(const const char* topic, String& payload, bool retain, uint8_t qos, bool dup) {
277+
publish(topic, payload.c_str(), retain, qos, dup);
278+
}
279+
280+
int MqttClient::publish(const String& topic, String& payload, bool retain, uint8_t qos, bool dup){
281+
publish(topic.c_str(), payload.c_str(), retain, qos, dup);
282+
}
283+
262284
int MqttClient::beginWill(const char* topic, unsigned short size, bool retain, uint8_t qos)
263285
{
264286
int topicLength = strlen(topic);

src/MqttClient.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ class MqttClient : public Client {
6464
int beginMessage(const char* topic, bool retain = false, uint8_t qos = 0, bool dup = false);
6565
int beginMessage(const String& topic, bool retain = false, uint8_t qos = 0, bool dup = false);
6666
int endMessage();
67+
int publish(const char* topic, const char* payload, bool retain = false, uint8_t qos = 0, bool dup = false);
68+
int publish(const String& topic, const char* payload, bool retain = false, uint8_t qos = 0, bool dup = false);
69+
int publish(const const char* topic, String& payload, bool retain = false, uint8_t qos = 0, bool dup = false);
70+
int publish(const String& topic, String& payload, bool retain = false, uint8_t qos = 0, bool dup = false);
6771

6872
int beginWill(const char* topic, unsigned short size, bool retain, uint8_t qos);
6973
int beginWill(const String& topic, unsigned short size, bool retain, uint8_t qos);

0 commit comments

Comments
 (0)