From 946f6fd74f6569d2bcdbbc1e006ad6638d2ac223 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Sun, 15 Dec 2019 16:40:02 -0300 Subject: [PATCH 1/2] PubSubClient: Add disconnect type option --- lib/PubSubClient-EspEasy-2.7.12/src/PubSubClient.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/PubSubClient-EspEasy-2.7.12/src/PubSubClient.cpp b/lib/PubSubClient-EspEasy-2.7.12/src/PubSubClient.cpp index 68cc2dafa..0748fdc4a 100644 --- a/lib/PubSubClient-EspEasy-2.7.12/src/PubSubClient.cpp +++ b/lib/PubSubClient-EspEasy-2.7.12/src/PubSubClient.cpp @@ -610,11 +610,13 @@ boolean PubSubClient::unsubscribe(const char* topic) { return false; } -void PubSubClient::disconnect() { +void PubSubClient::disconnect(bool disconnect_package) { buffer[0] = MQTTDISCONNECT; buffer[1] = 0; if (_client != nullptr) { - _client->write(buffer,2); + if (disconnect_package) { + _client->write(buffer,2); + } _client->flush(); _client->stop(); } From 08032944b2d596d0020fe23b0506b9583038b89f Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Sun, 15 Dec 2019 16:45:03 -0300 Subject: [PATCH 2/2] PubSubClient: Add disconnect type option Allow clean disconnect as optional. This avoid the automatic deletion of LWT message in the broker for clean disconnections, in order to let LWT work also on all cases (Restart, Config Changes, etc) See https://github.com/arendst/Tasmota/issues/7189 --- lib/PubSubClient-EspEasy-2.7.12/src/PubSubClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/PubSubClient-EspEasy-2.7.12/src/PubSubClient.h b/lib/PubSubClient-EspEasy-2.7.12/src/PubSubClient.h index aa2080ed1..593077e8c 100644 --- a/lib/PubSubClient-EspEasy-2.7.12/src/PubSubClient.h +++ b/lib/PubSubClient-EspEasy-2.7.12/src/PubSubClient.h @@ -141,7 +141,7 @@ public: boolean connect(const char* id, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage); boolean connect(const char* id, const char* user, const char* pass, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage); boolean connect(const char* id, const char* user, const char* pass, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage, boolean cleanSession); - void disconnect(); + void disconnect(bool disconnect_package = false); boolean publish(const char* topic, const char* payload); boolean publish(const char* topic, const char* payload, boolean retained); boolean publish(const char* topic, const uint8_t * payload, unsigned int plength);