Fixed some issues with raw payload

This commit is contained in:
Gunnar Skjold
2025-10-23 07:53:02 +02:00
parent 416efef681
commit 2a3748e886
5 changed files with 36 additions and 38 deletions

View File

@@ -205,24 +205,19 @@ float PriceService::getEnergyPricePoint(uint8_t direction, uint8_t point) {
}
float PriceService::getPriceForRelativeHour(uint8_t direction, int8_t hour) {
float value = getFixedPrice(direction, hour);
if(value != PRICE_NO_VALUE) return value;
if(today == NULL) return PRICE_NO_VALUE;
time_t ts = time(nullptr);
tmElements_t tm;
breakTime(tz->toLocal(ts), tm);
int8_t targetHour = tm.Hour + hour;
tm.Hour = tm.Minute = tm.Second = 0;
time_t startOfDay = makeTime(tm);
time_t startOfDay = tz->toUTC(makeTime(tm));
if(makeTime(tm) < startOfDay) {
if((ts + (hour * SECS_PER_HOUR)) < startOfDay) {
return PRICE_NO_VALUE;
}
breakTime(tz->toLocal(ts), tm);
int8_t targetHour = tm.Hour + hour;
if(today->getResolutionInMinutes() == 60) {
if(getResolutionInMinutes() == 60) {
return getPricePoint(direction, targetHour);
}

View File

@@ -320,28 +320,30 @@ bool RawMqttHandler::publishPrices(PriceService* ps) {
mqtt.publish(topic + "/price/resolution", String(ps->getResolutionInMinutes()), true, 0);
mqtt.loop();
uint8_t relativeIndex = 0;
uint8_t startIndex = ps->getCurrentPricePointIndex();
uint8_t numberOfPoints = ps->getNumberOfPointsAvailable();
for(int i = startIndex; i < numberOfPoints; i++) {
float importVal = ps->getPricePoint(PRICE_DIRECTION_IMPORT, i);
if(importVal == PRICE_NO_VALUE) {
mqtt.publish(topic + "/price/import/" + String(i), "", true, 0);
mqtt.publish(topic + "/price/import/" + String(relativeIndex), "", true, 0);
mqtt.loop();
} else {
mqtt.publish(topic + "/price/import/" + String(i), String(importVal, 4), true, 0);
mqtt.publish(topic + "/price/import/" + String(relativeIndex), String(importVal, 4), true, 0);
mqtt.loop();
}
if(hasExport && ps->isExportPricesDifferentFromImport()) {
float exportVal = ps->getPricePoint(PRICE_DIRECTION_EXPORT, i);
if(exportVal == PRICE_NO_VALUE) {
mqtt.publish(topic + "/price/export/" + String(i), "", true, 0);
mqtt.publish(topic + "/price/export/" + String(relativeIndex), "", true, 0);
mqtt.loop();
} else {
mqtt.publish(topic + "/price/export/" + String(i), String(exportVal, 4), true, 0);
mqtt.publish(topic + "/price/export/" + String(relativeIndex), String(exportVal, 4), true, 0);
mqtt.loop();
}
}
relativeIndex++;
}
if(min != INT16_MAX) {
mqtt.publish(topic + "/price/min", String(min, 4), true, 0);

File diff suppressed because one or more lines are too long

View File

@@ -41,7 +41,7 @@
min = max = 0;
let i = Math.floor(((cur.getHours()*60) + cur.getMinutes()) / json?.resolution);
cur.setMinutes(Math.floor(cur.getMinutes()/json?.resolution)*json?.resolution,0,0);
while(i++ < json?.prices?.length) {
while(i < json?.prices?.length) {
val = json.prices[i];
if(val == null) break;
xTicks.push({
@@ -51,6 +51,7 @@
min = Math.min(min, val*100);
max = Math.max(max, val*100);
addMinutes(cur, json?.resolution);
i++;
}
let ret = formatCurrency(Math.max(Math.abs(min) / 100.0, Math.abs(max) / 100.0), currency);

View File

@@ -17,29 +17,29 @@ export default defineConfig({
plugins: [svelte()],
server: {
proxy: {
"/data.json": "http://192.168.21.122",
"/energyprice.json": "http://192.168.21.122",
"/importprice.json": "http://192.168.21.122",
"/exportprice.json": "http://192.168.21.122",
"/dayplot.json": "http://192.168.21.122",
"/monthplot.json": "http://192.168.21.122",
"/temperature.json": "http://192.168.21.122",
"/sysinfo.json": "http://192.168.21.122",
"/configuration.json": "http://192.168.21.122",
"/tariff.json": "http://192.168.21.122",
"/realtime.json": "http://192.168.21.122",
"/priceconfig.json": "http://192.168.21.122",
"/translations.json": "http://192.168.21.122",
"/cloudkey.json": "http://192.168.21.122",
"/wifiscan.json": "http://192.168.21.122",
"/save": "http://192.168.21.122",
"/reboot": "http://192.168.21.122",
"/configfile": "http://192.168.21.122",
"/upgrade": "http://192.168.21.122",
"/mqtt-ca": "http://192.168.21.122",
"/mqtt-cert": "http://192.168.21.122",
"/mqtt-key": "http://192.168.21.122",
"/logo.svg": "http://192.168.21.122",
"/data.json": "http://192.168.233.49",
"/energyprice.json": "http://192.168.233.49",
"/importprice.json": "http://192.168.233.49",
"/exportprice.json": "http://192.168.233.49",
"/dayplot.json": "http://192.168.233.49",
"/monthplot.json": "http://192.168.233.49",
"/temperature.json": "http://192.168.233.49",
"/sysinfo.json": "http://192.168.233.49",
"/configuration.json": "http://192.168.233.49",
"/tariff.json": "http://192.168.233.49",
"/realtime.json": "http://192.168.233.49",
"/priceconfig.json": "http://192.168.233.49",
"/translations.json": "http://192.168.233.49",
"/cloudkey.json": "http://192.168.233.49",
"/wifiscan.json": "http://192.168.233.49",
"/save": "http://192.168.233.49",
"/reboot": "http://192.168.233.49",
"/configfile": "http://192.168.233.49",
"/upgrade": "http://192.168.233.49",
"/mqtt-ca": "http://192.168.233.49",
"/mqtt-cert": "http://192.168.233.49",
"/mqtt-key": "http://192.168.233.49",
"/logo.svg": "http://192.168.233.49",
}
}
})