From 3e21105b2df8601fb5b23dfc2ed3d891326b579b Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Wed, 17 Mar 2021 20:33:11 +0100 Subject: [PATCH] Fixed prices in JSON handler --- src/mqtt/JsonMqttHandler.cpp | 20 +++++++++++++------- web/jsonprices.json | 1 - 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/mqtt/JsonMqttHandler.cpp b/src/mqtt/JsonMqttHandler.cpp index 6774cde9..6382dc46 100644 --- a/src/mqtt/JsonMqttHandler.cpp +++ b/src/mqtt/JsonMqttHandler.cpp @@ -118,7 +118,7 @@ bool JsonMqttHandler::publishPrices(EntsoeApi* eapi) { time_t now = time(nullptr); float min1hr, min3hr, min6hr; - uint8_t min1hrIdx = -1, min3hrIdx = -1, min6hrIdx = -1; + int8_t min1hrIdx = -1, min3hrIdx = -1, min6hrIdx = -1; float min = INT16_MAX, max = INT16_MIN; float values[24] = {0}; for(uint8_t i = 0; i < 24; i++) { @@ -167,21 +167,27 @@ bool JsonMqttHandler::publishPrices(EntsoeApi* eapi) { } char ts1hr[21]; - if(min1hrIdx != -1) { + if(min1hrIdx > -1) { + time_t ts = now + (SECS_PER_HOUR * min1hrIdx); + //Serial.printf("1hr: %d %lu\n", min1hrIdx, ts); tmElements_t tm; - breakTime(now + (SECS_PER_HOUR * min1hrIdx), tm); + breakTime(ts, tm); sprintf(ts1hr, "%04d-%02d-%02dT%02d:00:00Z", tm.Year+1970, tm.Month, tm.Day, tm.Hour); } char ts3hr[21]; - if(min3hrIdx != -1) { + if(min3hrIdx > -1) { + time_t ts = now + (SECS_PER_HOUR * min3hrIdx); + //Serial.printf("3hr: %d %lu\n", min3hrIdx, ts); tmElements_t tm; - breakTime(now + (SECS_PER_HOUR * min3hrIdx), tm); + breakTime(ts, tm); sprintf(ts3hr, "%04d-%02d-%02dT%02d:00:00Z", tm.Year+1970, tm.Month, tm.Day, tm.Hour); } char ts6hr[21]; - if(min6hrIdx != -1) { + if(min6hrIdx > -1) { + time_t ts = now + (SECS_PER_HOUR * min6hrIdx); + //Serial.printf("6hr: %d %lu\n", min6hrIdx, ts); tmElements_t tm; - breakTime(now + (SECS_PER_HOUR * min6hrIdx), tm); + breakTime(ts, tm); sprintf(ts6hr, "%04d-%02d-%02dT%02d:00:00Z", tm.Year+1970, tm.Month, tm.Day, tm.Hour); } diff --git a/web/jsonprices.json b/web/jsonprices.json index f9823c3f..293039ce 100644 --- a/web/jsonprices.json +++ b/web/jsonprices.json @@ -13,7 +13,6 @@ "9" : %.4f, "10" : %.4f, "11" : %.4f, - "12" : %.4f, "min" : %.4f, "max" : %.4f, "cheapest1hr" : "%s",