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