mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-10 18:24:27 +05:00
added check for success of PubSubClient::beginPublish()
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<MqttTask*>(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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user