Fixed loading order of json and when to display price graph

This commit is contained in:
Gunnar Skjold 2024-05-23 19:12:38 +02:00
parent 703c68a2cf
commit faa468b287
5 changed files with 33 additions and 31 deletions

File diff suppressed because one or more lines are too long

View File

@ -70,7 +70,6 @@
getTranslations(sysinfo.ui.lang);
}
});
getSysinfo();
let data = {};
dataStore.subscribe(update => {

View File

@ -26,12 +26,15 @@ let sysinfo = {
eth: false
}
};
export const sysinfoStore = writable(sysinfo);
export async function getSysinfo() {
const response = await fetchWithTimeout("sysinfo.json?t=" + Math.floor(Date.now() / 1000));
sysinfo = (await response.json())
sysinfoStore.set(sysinfo);
};
export const sysinfoStore = writable(sysinfo, (set) => {
getSysinfo();
return function stop() {}
});
function updateSysinfo(url) {
sysinfoStore.update(s => {
@ -69,6 +72,9 @@ export const dataStore = readable(data, (set) => {
if(monthPlotTimeout) clearTimeout(monthPlotTimeout);
monthPlotTimeout = setTimeout(getMonthPlot, 3000);
}
if(!dayPlotTimeout) dayPlotTimeout = getDayPlot();
if(!monthPlotTimeout) monthPlotTimeout = getMonthPlot();
let to = 5000;
if(isBusPowered(sysinfo.board) && data.v > 2.5) {
let diff = (3.3 - Math.min(3.3, data.v));
@ -156,7 +162,6 @@ export async function getDayPlot() {
}
export const dayPlotStore = writable(dayPlot, (set) => {
getDayPlot();
return function stop() {}
});
@ -176,7 +181,6 @@ export async function getMonthPlot() {
}
export const monthPlotStore = writable(monthPlot, (set) => {
getMonthPlot();
return function stop() {}
});
@ -188,7 +192,6 @@ export async function getTemperatures() {
}
export const temperaturesStore = writable(temperatures, (set) => {
getTemperatures();
return function stop() {}
});

View File

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

View File

@ -601,7 +601,7 @@ void AmsWebServer::dataJson() {
ea->getCostThisMonth(),
ea->getProducedThisMonth(),
ea->getIncomeThisMonth(),
ps == NULL ? "false" : "true",
price == PRICE_NO_VALUE ? "false" : "true",
priceRegion.c_str(),
priceCurrency.c_str(),
meterState->getLastError(),