diff --git a/lib/HomeAssistantHelper/HomeAssistantHelper.h b/lib/HomeAssistantHelper/HomeAssistantHelper.h index 81cae9f..8e73c49 100644 --- a/lib/HomeAssistantHelper/HomeAssistantHelper.h +++ b/lib/HomeAssistantHelper/HomeAssistantHelper.h @@ -70,7 +70,14 @@ public: doc[FPSTR(HA_DEVICE)][FPSTR(HA_CONF_URL)] = deviceConfigUrl; } - client->beginPublish(topic, measureJson(doc), true); + if (!client->beginPublish(topic, measureJson(doc), true)) { + if (this->yieldCallback != nullptr) { + this->yieldCallback(yieldArg); + } + + return false; + } + if (this->bClient != nullptr) { serializeJson(doc, *this->bClient); this->bClient->flush(); @@ -78,7 +85,7 @@ public: } else { serializeJson(doc, *client); } - + int pubResult = client->endPublish(); if (this->yieldCallback != nullptr) { this->yieldCallback(yieldArg); diff --git a/platformio.ini b/platformio.ini index 7ea1684..f686dec 100644 --- a/platformio.ini +++ b/platformio.ini @@ -18,7 +18,7 @@ lib_deps = knolleary/PubSubClient@^2.8 bblanchon/StreamUtils@^1.7.3 ;lennarthennigs/ESP Telnet@^2.1.2 - https://github.com/Laxilef/ESPTelnet + https://github.com/Laxilef/ESPTelnet/archive/refs/heads/master.zip gyverlibs/EEManager@^2.0 gyverlibs/GyverPID@^3.3 gyverlibs/GyverBlinker@^1.0 diff --git a/src/MqttTask.h b/src/MqttTask.h index e8c8c8a..1a31b40 100644 --- a/src/MqttTask.h +++ b/src/MqttTask.h @@ -38,10 +38,11 @@ protected: void setup() { Log.sinfoln("MQTT", F("Started")); - this->bClient = new BufferingPrint(client, 32); + this->bClient = new BufferingPrint(client, 64); client.setCallback(std::bind(&MqttTask::__callback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); client.setBufferSize(1024); + client.setSocketTimeout(1); haHelper.setYieldCallback([](void* self) { MqttTask* task = static_cast(self); @@ -618,9 +619,13 @@ protected: doc["sensors"]["indoor"]["type"] = settings.sensors.indoor.type; doc["sensors"]["indoor"]["offset"] = settings.sensors.indoor.offset; - client.beginPublish(topic, measureJson(doc), false); + if (!client.beginPublish(topic, measureJson(doc), false)) { + return false; + } + serializeJson(doc, *this->bClient); this->bClient->flush(); + return client.endPublish(); } @@ -656,9 +661,13 @@ protected: doc["parameters"]["dhwMinTemp"] = vars.parameters.dhwMinTemp; doc["parameters"]["dhwMaxTemp"] = vars.parameters.dhwMaxTemp; - client.beginPublish(topic, measureJson(doc), false); + if (!client.beginPublish(topic, measureJson(doc), false)) { + return false; + } + serializeJson(doc, *this->bClient); this->bClient->flush(); + return client.endPublish(); }