mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-11 18:54:28 +05:00
added buffer for writing to mqtt
This commit is contained in:
@@ -1,11 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <StreamUtils.h>
|
||||||
|
|
||||||
class HomeAssistantHelper {
|
class HomeAssistantHelper {
|
||||||
public:
|
public:
|
||||||
HomeAssistantHelper(PubSubClient& client) :
|
HomeAssistantHelper(PubSubClient& client) {
|
||||||
client(&client)
|
this->client = &client;
|
||||||
{
|
}
|
||||||
|
|
||||||
|
void setBufferedClient() {
|
||||||
|
this->bClient = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBufferedClient(BufferingPrint* bClient) {
|
||||||
|
this->bClient = bClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDevicePrefix(String value) {
|
void setDevicePrefix(String value) {
|
||||||
@@ -52,11 +60,14 @@ public:
|
|||||||
doc[FPSTR(HA_DEVICE)][FPSTR(HA_CONF_URL)] = deviceConfigUrl;
|
doc[FPSTR(HA_DEVICE)][FPSTR(HA_CONF_URL)] = deviceConfigUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Feeding the watchdog
|
|
||||||
yield();
|
|
||||||
|
|
||||||
client->beginPublish(topic, measureJson(doc), true);
|
client->beginPublish(topic, measureJson(doc), true);
|
||||||
serializeJson(doc, *client);
|
if (this->bClient != nullptr) {
|
||||||
|
serializeJson(doc, *this->bClient);
|
||||||
|
this->bClient->flush();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
serializeJson(doc, *client);
|
||||||
|
}
|
||||||
return client->endPublish();
|
return client->endPublish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +90,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
PubSubClient* client;
|
PubSubClient* client;
|
||||||
|
BufferingPrint* bClient = nullptr;
|
||||||
String prefix = "homeassistant";
|
String prefix = "homeassistant";
|
||||||
String devicePrefix = "";
|
String devicePrefix = "";
|
||||||
String deviceVersion = "1.0";
|
String deviceVersion = "1.0";
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ lib_deps =
|
|||||||
bblanchon/ArduinoJson@^6.20.0
|
bblanchon/ArduinoJson@^6.20.0
|
||||||
ihormelnyk/OpenTherm Library@^1.1.4
|
ihormelnyk/OpenTherm Library@^1.1.4
|
||||||
knolleary/PubSubClient@^2.8
|
knolleary/PubSubClient@^2.8
|
||||||
|
bblanchon/StreamUtils@^1.7.3
|
||||||
lennarthennigs/ESP Telnet@^2.1.2
|
lennarthennigs/ESP Telnet@^2.1.2
|
||||||
gyverlibs/EEManager@^2.0
|
gyverlibs/EEManager@^2.0
|
||||||
gyverlibs/GyverPID@^3.3
|
gyverlibs/GyverPID@^3.3
|
||||||
|
|||||||
Reference in New Issue
Block a user