Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/PubSubClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "PubSubClient.h"
#include <string.h>

PubSubClient::PubSubClient(){}

PubSubClient::PubSubClient(Client& c) :
_callback(NULL),
_client(&c),
Expand Down Expand Up @@ -227,6 +229,15 @@ bool PubSubClient::publish(String topic, String payload) {
return publish(pub);
}

bool PubSubClient::publish(String topic, String payload, bool retained) {
if (!connected())
return false;

MQTT::Publish pub(topic, payload);
pub.set_retain(retained);
return publish(pub);
}

bool PubSubClient::publish(String topic, const uint8_t* payload, uint32_t plength, bool retained) {
if (!connected())
return false;
Expand Down
9 changes: 9 additions & 0 deletions src/PubSubClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class PubSubClient {
/*!
Use set_server() before connect()
*/
PubSubClient();
PubSubClient(Client& c);

//! Constructor with the server ip address
Expand Down Expand Up @@ -131,6 +132,14 @@ class PubSubClient {
*/
bool publish(String topic, String payload);

//! Publish a string payload
/*!
\param topic Topic of the message
\param payload String text of the message
\param retained If true, this message will be stored on the server and
*/
bool publish(String topic, String payload, bool retained);

//! Publish an arbitrary data payload
/*!
\param topic Topic of the message
Expand Down