data topic cleanup

This commit is contained in:
Patrick Haßel 2024-04-15 14:30:29 +02:00
parent b298f84271
commit 3a09b61685
4 changed files with 8 additions and 12 deletions

View File

@ -23,8 +23,6 @@ private:
T data;
};
const char *name;
Entry buffer[size];
Entry *bufferRead = buffer;
@ -36,7 +34,7 @@ private:
public:
template<typename U = T, typename = ExtendsIData<U>>
explicit Cache(const char *name) : name(name) {
explicit Cache() {
// -
}
@ -59,17 +57,17 @@ public:
json["timestamp"] = correctTime(bufferRead->timestamp);
JsonObject data = json["data"].to<JsonObject>();
bufferRead->data.toJson(data);
if (mqttPublishData(name, json)) {
if (mqttPublishData(json)) {
bufferRead = (bufferRead - buffer + 1) % size + buffer;
usage--;
}
}
size_t getUsage() const {
[[nodiscard]] size_t getUsage() const {
return usage;
}
size_t getSize() const {
[[nodiscard]] size_t getSize() const {
return size;
}

View File

@ -90,13 +90,11 @@ void mqttPublishLog(const char *datetime, const char *header, const char *messag
}
}
bool mqttPublishData(const char *name, const JsonDocument &doc) {
bool mqttPublishData(const JsonDocument &doc) {
if (mqtt.connected()) {
char topic[128];
snprintf(topic, sizeof topic, TOPIC_DATA_FORMAT, HOSTNAME, name);
char payload[512];
const size_t size = serializeJson(doc, payload);
boolean result = mqtt.publish(topic, payload, size);
boolean result = mqtt.publish(HOSTNAME, payload, size);
yield();
return result;
}

View File

@ -11,6 +11,6 @@ void mqttDisconnect();
void mqttPublishLog(const char *datetime, const char *header, const char *message);
bool mqttPublishData(const char *name, const JsonDocument &doc);
bool mqttPublishData(const JsonDocument &doc);
#endif

View File

@ -43,7 +43,7 @@ double temperatureCurrent = NAN;
double heaterPWM = 0;
Cache<FermenterData, 500> cache("data");
Cache<FermenterData, 500> cache;
void writeDecimal(int *digit, double value);