From 9f4fed1584c8b5c1abb61ee405fb0faefb1aa555 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 23 Oct 2018 17:07:43 +0200 Subject: [PATCH] Update PubSubClient lib Add delay when waiting for data and flush on disconnect --- lib/PubSubClient-EspEasy-2.6.09/src/PubSubClient.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/PubSubClient-EspEasy-2.6.09/src/PubSubClient.cpp b/lib/PubSubClient-EspEasy-2.6.09/src/PubSubClient.cpp index 7d1d3e102..79eb2d52e 100644 --- a/lib/PubSubClient-EspEasy-2.6.09/src/PubSubClient.cpp +++ b/lib/PubSubClient-EspEasy-2.6.09/src/PubSubClient.cpp @@ -209,6 +209,7 @@ boolean PubSubClient::connect(const char *id, const char *user, const char *pass boolean PubSubClient::readByte(uint8_t * result) { uint32_t previousMillis = millis(); while(!_client->available()) { + delay(1); // Add esp8266 de-blocking (Tasmota #790, EspEasy #1943) uint32_t currentMillis = millis(); if(currentMillis - previousMillis >= ((int32_t) MQTT_SOCKET_TIMEOUT * 1000)){ return false; @@ -522,9 +523,12 @@ boolean PubSubClient::unsubscribe(const char* topic) { void PubSubClient::disconnect() { buffer[0] = MQTTDISCONNECT; buffer[1] = 0; - _client->write(buffer,2); + if (_client != NULL) { + _client->write(buffer,2); + _client->flush(); + _client->stop(); + } _state = MQTT_DISCONNECTED; - _client->stop(); lastInActivity = lastOutActivity = millis(); }