From 8653931542bbac424941e8bd875aefe86778c094 Mon Sep 17 00:00:00 2001 From: doebi Date: Wed, 2 Sep 2015 23:54:32 +0200 Subject: [PATCH 1/2] added simple publish method with retained flag --- src/PubSubClient.cpp | 9 +++++++++ src/PubSubClient.h | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/src/PubSubClient.cpp b/src/PubSubClient.cpp index 43d5ef0a..2106987e 100644 --- a/src/PubSubClient.cpp +++ b/src/PubSubClient.cpp @@ -227,6 +227,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..5854ff33 100644 --- a/src/PubSubClient.h +++ b/src/PubSubClient.h @@ -131,6 +131,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 From 4cb975a21a122605653bc82bae1cd57b853b4884 Mon Sep 17 00:00:00 2001 From: doebi Date: Sun, 3 Jan 2016 13:47:40 +0100 Subject: [PATCH 2/2] added default constructor --- src/PubSubClient.cpp | 2 ++ src/PubSubClient.h | 1 + 2 files changed, 3 insertions(+) diff --git a/src/PubSubClient.cpp b/src/PubSubClient.cpp index 2106987e..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), diff --git a/src/PubSubClient.h b/src/PubSubClient.h index 5854ff33..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