|
|
|
|
@@ -79,19 +79,20 @@ bool RawMqttHandler::publishTemperatures(AmsConfiguration* config, HwTools* hw)
|
|
|
|
|
bool RawMqttHandler::publishPrices(EntsoeApi* eapi) {
|
|
|
|
|
if(topic.isEmpty() || !mqtt->connected())
|
|
|
|
|
return false;
|
|
|
|
|
if(strcmp(eapi->getToken(), "") != 0)
|
|
|
|
|
if(strcmp(eapi->getToken(), "") == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
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++) {
|
|
|
|
|
float values[34] = {0};
|
|
|
|
|
for(uint8_t i = 0; i < 34; i++) {
|
|
|
|
|
float val = eapi->getValueForHour(now, i);
|
|
|
|
|
values[i] = val;
|
|
|
|
|
|
|
|
|
|
if(i > 23) continue;
|
|
|
|
|
if(val == ENTSOE_NO_VALUE) break;
|
|
|
|
|
|
|
|
|
|
if(val < min) min = val;
|
|
|
|
|
@@ -134,50 +135,56 @@ bool RawMqttHandler::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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 24; i++) {
|
|
|
|
|
for(int i = 0; i < 34; i++) {
|
|
|
|
|
float val = values[i];
|
|
|
|
|
if(val == ENTSOE_NO_VALUE) {
|
|
|
|
|
mqtt->publish(topic + "/price/" + String(i), "");
|
|
|
|
|
mqtt->publish(topic + "/price/" + String(i), "", true, 0);
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
mqtt->publish(topic + "/price/" + String(i), String(val, 4));
|
|
|
|
|
mqtt->publish(topic + "/price/" + String(i), String(val, 4), true, 0);
|
|
|
|
|
}
|
|
|
|
|
mqtt->loop();
|
|
|
|
|
delay(10);
|
|
|
|
|
}
|
|
|
|
|
if(min != INT16_MAX) {
|
|
|
|
|
mqtt->publish(topic + "/price/min", String(min, 4));
|
|
|
|
|
mqtt->publish(topic + "/price/min", String(min, 4), true, 0);
|
|
|
|
|
}
|
|
|
|
|
if(max != INT16_MIN) {
|
|
|
|
|
mqtt->publish(topic + "/price/max", String(max, 4));
|
|
|
|
|
mqtt->publish(topic + "/price/max", String(max, 4), true, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(min1hrIdx != -1) {
|
|
|
|
|
mqtt->publish(topic + "/price/cheapest/1hr", String(ts1hr));
|
|
|
|
|
mqtt->publish(topic + "/price/cheapest/1hr", String(ts1hr), true, 0);
|
|
|
|
|
}
|
|
|
|
|
if(min3hrIdx != -1) {
|
|
|
|
|
mqtt->publish(topic + "/price/cheapest/3hr", String(ts3hr));
|
|
|
|
|
mqtt->publish(topic + "/price/cheapest/3hr", String(ts3hr), true, 0);
|
|
|
|
|
}
|
|
|
|
|
if(min6hrIdx != -1) {
|
|
|
|
|
mqtt->publish(topic + "/price/cheapest/6hr", String(ts6hr));
|
|
|
|
|
mqtt->publish(topic + "/price/cheapest/6hr", String(ts6hr), true, 0);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
@@ -186,7 +193,7 @@ bool RawMqttHandler::publishSystem(HwTools* hw) {
|
|
|
|
|
if(topic.isEmpty() || !mqtt->connected())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
mqtt->publish(topic + "/id", WiFi.macAddress());
|
|
|
|
|
mqtt->publish(topic + "/id", WiFi.macAddress(), true, 0);
|
|
|
|
|
mqtt->publish(topic + "/uptime", String((unsigned long) millis64()/1000));
|
|
|
|
|
float vcc = hw->getVcc();
|
|
|
|
|
if(vcc > 0) {
|
|
|
|
|
|