Added tariff peaks and total month to MQTT JSON payload (#1026)

* Added tariff peaks to MQTT JSON payload

* Bugfix after testing
This commit is contained in:
Gunnar Skjold 2025-10-02 13:11:28 +02:00 committed by GitHub
parent b06aa5f71b
commit e3a1aa78a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -79,14 +79,24 @@ uint16_t JsonMqttHandler::appendJsonFooter(EnergyAccounting* ea, uint16_t pos) {
} else { } else {
memset(pf, 0, 4); memset(pf, 0, 4);
} }
String peaks = "";
uint8_t peakCount = ea->getConfig()->hours;
if(peakCount > 5) peakCount = 5;
for(uint8_t i = 1; i <= peakCount; i++) {
if(!peaks.isEmpty()) peaks += ",";
peaks += String(ea->getPeak(i).value / 100.0, 2);
}
return snprintf_P(json+pos, BufferSize-pos, PSTR("%s\"%sh\":%.2f,\"%sd\":%.1f,\"%st\":%d,\"%sx\":%.2f,\"%she\":%.2f,\"%sde\":%.1f%s"), return snprintf_P(json+pos, BufferSize-pos, PSTR("%s\"%sh\":%.3f,\"%sd\":%.2f,\"%sm\":%.1f,\"%st\":%d,\"%sx\":%.2f,\"%she\":%.3f,\"%sde\":%.2f,\"%sme\":%.1f,\"peaks\":[%s]%s"),
strlen(pf) == 0 ? "},\"realtime\":{" : ",", strlen(pf) == 0 ? "},\"realtime\":{" : ",",
pf, pf,
ea->getUseThisHour(), ea->getUseThisHour(),
pf, pf,
ea->getUseToday(), ea->getUseToday(),
pf, pf,
ea->getUseThisMonth(),
pf,
ea->getCurrentThreshold(), ea->getCurrentThreshold(),
pf, pf,
ea->getMonthMax(), ea->getMonthMax(),
@ -94,6 +104,9 @@ uint16_t JsonMqttHandler::appendJsonFooter(EnergyAccounting* ea, uint16_t pos) {
ea->getProducedThisHour(), ea->getProducedThisHour(),
pf, pf,
ea->getProducedToday(), ea->getProducedToday(),
pf,
ea->getProducedThisMonth(),
peaks.c_str(),
strlen(pf) == 0 ? "}" : "" strlen(pf) == 0 ? "}" : ""
); );
} }