diff --git a/src/PubSubClient.cpp b/src/PubSubClient.cpp index 43d5ef0a..e787b300 100644 --- a/src/PubSubClient.cpp +++ b/src/PubSubClient.cpp @@ -7,6 +7,8 @@ #include "PubSubClient.h" #include +PubSubClient::PubSubClient(){} + PubSubClient::PubSubClient(Client& c) : _callback(NULL), _client(&c), @@ -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; diff --git a/src/PubSubClient.h b/src/PubSubClient.h index ab093368..a4dc3cda 100644 --- a/src/PubSubClient.h +++ b/src/PubSubClient.h @@ -81,6 +81,7 @@ class PubSubClient { /*! Use set_server() before connect() */ + PubSubClient(); PubSubClient(Client& c); //! Constructor with the server ip address @@ -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