data topic cleanup
This commit is contained in:
parent
b298f84271
commit
3a09b61685
@ -23,8 +23,6 @@ private:
|
|||||||
T data;
|
T data;
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *name;
|
|
||||||
|
|
||||||
Entry buffer[size];
|
Entry buffer[size];
|
||||||
|
|
||||||
Entry *bufferRead = buffer;
|
Entry *bufferRead = buffer;
|
||||||
@ -36,7 +34,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
template<typename U = T, typename = ExtendsIData<U>>
|
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);
|
json["timestamp"] = correctTime(bufferRead->timestamp);
|
||||||
JsonObject data = json["data"].to<JsonObject>();
|
JsonObject data = json["data"].to<JsonObject>();
|
||||||
bufferRead->data.toJson(data);
|
bufferRead->data.toJson(data);
|
||||||
if (mqttPublishData(name, json)) {
|
if (mqttPublishData(json)) {
|
||||||
bufferRead = (bufferRead - buffer + 1) % size + buffer;
|
bufferRead = (bufferRead - buffer + 1) % size + buffer;
|
||||||
usage--;
|
usage--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getUsage() const {
|
[[nodiscard]] size_t getUsage() const {
|
||||||
return usage;
|
return usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getSize() const {
|
[[nodiscard]] size_t getSize() const {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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()) {
|
if (mqtt.connected()) {
|
||||||
char topic[128];
|
|
||||||
snprintf(topic, sizeof topic, TOPIC_DATA_FORMAT, HOSTNAME, name);
|
|
||||||
char payload[512];
|
char payload[512];
|
||||||
const size_t size = serializeJson(doc, payload);
|
const size_t size = serializeJson(doc, payload);
|
||||||
boolean result = mqtt.publish(topic, payload, size);
|
boolean result = mqtt.publish(HOSTNAME, payload, size);
|
||||||
yield();
|
yield();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,6 @@ void mqttDisconnect();
|
|||||||
|
|
||||||
void mqttPublishLog(const char *datetime, const char *header, const char *message);
|
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
|
#endif
|
||||||
|
|||||||
@ -43,7 +43,7 @@ double temperatureCurrent = NAN;
|
|||||||
|
|
||||||
double heaterPWM = 0;
|
double heaterPWM = 0;
|
||||||
|
|
||||||
Cache<FermenterData, 500> cache("data");
|
Cache<FermenterData, 500> cache;
|
||||||
|
|
||||||
void writeDecimal(int *digit, double value);
|
void writeDecimal(int *digit, double value);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user