mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-11 18:54:28 +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;
|
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) {
|
if (this->bClient != nullptr) {
|
||||||
serializeJson(doc, *this->bClient);
|
serializeJson(doc, *this->bClient);
|
||||||
this->bClient->flush();
|
this->bClient->flush();
|
||||||
@@ -78,7 +85,7 @@ public:
|
|||||||
} else {
|
} else {
|
||||||
serializeJson(doc, *client);
|
serializeJson(doc, *client);
|
||||||
}
|
}
|
||||||
|
|
||||||
int pubResult = client->endPublish();
|
int pubResult = client->endPublish();
|
||||||
if (this->yieldCallback != nullptr) {
|
if (this->yieldCallback != nullptr) {
|
||||||
this->yieldCallback(yieldArg);
|
this->yieldCallback(yieldArg);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ lib_deps =
|
|||||||
knolleary/PubSubClient@^2.8
|
knolleary/PubSubClient@^2.8
|
||||||
bblanchon/StreamUtils@^1.7.3
|
bblanchon/StreamUtils@^1.7.3
|
||||||
;lennarthennigs/ESP Telnet@^2.1.2
|
;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/EEManager@^2.0
|
||||||
gyverlibs/GyverPID@^3.3
|
gyverlibs/GyverPID@^3.3
|
||||||
gyverlibs/GyverBlinker@^1.0
|
gyverlibs/GyverBlinker@^1.0
|
||||||
|
|||||||
@@ -38,10 +38,11 @@ protected:
|
|||||||
void setup() {
|
void setup() {
|
||||||
Log.sinfoln("MQTT", F("Started"));
|
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.setCallback(std::bind(&MqttTask::__callback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
||||||
client.setBufferSize(1024);
|
client.setBufferSize(1024);
|
||||||
|
client.setSocketTimeout(1);
|
||||||
|
|
||||||
haHelper.setYieldCallback([](void* self) {
|
haHelper.setYieldCallback([](void* self) {
|
||||||
MqttTask* task = static_cast<MqttTask*>(self);
|
MqttTask* task = static_cast<MqttTask*>(self);
|
||||||
@@ -618,9 +619,13 @@ protected:
|
|||||||
doc["sensors"]["indoor"]["type"] = settings.sensors.indoor.type;
|
doc["sensors"]["indoor"]["type"] = settings.sensors.indoor.type;
|
||||||
doc["sensors"]["indoor"]["offset"] = settings.sensors.indoor.offset;
|
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);
|
serializeJson(doc, *this->bClient);
|
||||||
this->bClient->flush();
|
this->bClient->flush();
|
||||||
|
|
||||||
return client.endPublish();
|
return client.endPublish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -656,9 +661,13 @@ protected:
|
|||||||
doc["parameters"]["dhwMinTemp"] = vars.parameters.dhwMinTemp;
|
doc["parameters"]["dhwMinTemp"] = vars.parameters.dhwMinTemp;
|
||||||
doc["parameters"]["dhwMaxTemp"] = vars.parameters.dhwMaxTemp;
|
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);
|
serializeJson(doc, *this->bClient);
|
||||||
this->bClient->flush();
|
this->bClient->flush();
|
||||||
|
|
||||||
return client.endPublish();
|
return client.endPublish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user