added check for success of PubSubClient::beginPublish()

This commit is contained in:
Yurii
2023-12-10 19:47:28 +03:00
parent be5f2b74bc
commit c048f31672
3 changed files with 22 additions and 6 deletions

View File

@@ -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);