diff --git a/lib/EnergyAccounting/include/EnergyAccounting.h b/lib/EnergyAccounting/include/EnergyAccounting.h index 912fd870..ab3dc026 100644 --- a/lib/EnergyAccounting/include/EnergyAccounting.h +++ b/lib/EnergyAccounting/include/EnergyAccounting.h @@ -89,8 +89,8 @@ private: EnergyAccountingConfig *config = NULL; Timezone *tz = NULL; uint8_t currentHour = 0, currentDay = 0, currentThresholdIdx = 0; - double use, costHour, costDay; - double produce, incomeHour, incomeDay; + double use = 0, costHour = 0, costDay = 0; + double produce = 0, incomeHour = 0, incomeDay = 0; EnergyAccountingData data = { 0, 0, 0, 0, 0, 0 }; void calcDayCost(); diff --git a/lib/SvelteUi/app/src/App.svelte b/lib/SvelteUi/app/src/App.svelte index dae7d266..96e7a160 100644 --- a/lib/SvelteUi/app/src/App.svelte +++ b/lib/SvelteUi/app/src/App.svelte @@ -64,6 +64,10 @@ {#if sysinfo.upgrading} {:else if sysinfo.booting} - + {#if sysinfo.trying} + + {:else} + + {/if} {/if} diff --git a/lib/SvelteUi/app/src/lib/AccountingData.svelte b/lib/SvelteUi/app/src/lib/AccountingData.svelte index c21dafbb..f354ce3a 100644 --- a/lib/SvelteUi/app/src/lib/AccountingData.svelte +++ b/lib/SvelteUi/app/src/lib/AccountingData.svelte @@ -1,54 +1,79 @@
Real time calculation - - {#if data && data.h !== undefined} -
-
Hour
-
{data.h.u ? data.h.u.toFixed(2) : '-'} kWh {#if currency && (hasExport)}/ {data.h.c ? data.h.c.toFixed(2) : '-'} {currency}{/if}
-
-
-
Day
-
{data.d.u ? data.d.u.toFixed(1) : '-'} kWh {#if currency && (hasExport)}/ {data.d.c ? data.d.c.toFixed(2) : '-'} {currency}{/if}
-
-
-
Month
-
{data.m.u ? data.m.u.toFixed(0) : '-'} kWh {#if currency && (hasExport)}/ {data.m.c ? data.m.c.toFixed(2) : '-'} {currency}{/if}
-
-
- {#if hasExport} -
-
Hour
-
{data.h.p ? data.h.p.toFixed(2) : '-'} kWh {#if currency}/ {data.h.i ? data.h.i.toFixed(2) : '-'} {currency}{/if}
-
-
-
Day
-
{data.d.p ? data.d.p.toFixed(1) : '-'} kWh {#if currency}/ {data.d.i ? data.d.i.toFixed(2) : '-'} {currency}{/if}
-
-
-
Month
-
{data.m.p ? data.m.p.toFixed(0) : '-'} kWh {#if currency}/ {data.m.i ? data.m.i.toFixed(2) : '-'} {currency}{/if}
-
+

+ + {#if data} + {#if hasExport && currency} + Import +
+
Hour
+
{data.h.u ? data.h.u.toFixed(2) : '-'} kWh
+
{data.h.c ? data.h.c.toFixed(2) : '-'} {currency}
+
Day
+
{data.d.u ? data.d.u.toFixed(1) : '-'} kWh
+
{data.d.c ? data.d.c.toFixed(1) : '-'} {currency}
+
Month
+
{data.m.u ? data.m.u.toFixed(0) : '-'} kWh
+
{data.m.c ? data.m.c.toFixed(0) : '-'} {currency}
+
+ Export +
+
Hour
+
{data.h.p ? data.h.p.toFixed(2) : '-'} kWh
+
{data.h.i ? data.h.i.toFixed(2) : '-'} {currency}
+
Day
+
{data.d.p ? data.d.p.toFixed(1) : '-'} kWh
+
{data.d.i ? data.d.i.toFixed(1) : '-'} {currency}
+
Month
+
{data.m.p ? data.m.p.toFixed(0) : '-'} kWh
+
{data.m.i ? data.m.i.toFixed(0) : '-'} {currency}
+
+ {:else if hasExport} + Import +
+
Hour
+
{data.h.u ? data.h.u.toFixed(2) : '-'} kWh
+
Day
+
{data.d.u ? data.d.u.toFixed(1) : '-'} kWh
+
Month
+
{data.m.u ? data.m.u.toFixed(0) : '-'} kWh
+
+ Export +
+
Hour
+
{data.h.p ? data.h.p.toFixed(2) : '-'} kWh
+
Day
+
{data.d.p ? data.d.p.toFixed(1) : '-'} kWh
+
Month
+
{data.m.p ? data.m.p.toFixed(0) : '-'} kWh
+
{:else} -
-
Hour
-
{data.h.c ? data.h.c.toFixed(2) : '-'} {currency}
-
-
-
Day
-
{data.d.c ? data.d.c.toFixed(2) : '-'} {currency}
-
-
-
Month
-
{data.m.c ? data.m.c.toFixed(2) : '-'} {currency}
-
+ Consumption +
+
Hour
+
{data.h.u ? data.h.u.toFixed(2) : '-'} kWh
+
Day
+
{data.d.u ? data.d.u.toFixed(1) : '-'} kWh
+
Month
+
{data.m.u ? data.m.u.toFixed(0) : '-'} kWh
+
+ {#if currency} + Cost +
+
Hour
+
{data.h.c ? data.h.c.toFixed(2) : '-'} {currency}
+
Day
+
{data.d.c ? data.d.c.toFixed(1) : '-'} {currency}
+
Month
+
{data.m.c ? data.m.c.toFixed(0) : '-'} {currency}
+
+ {/if} {/if} -
{/if}
\ No newline at end of file diff --git a/lib/SvelteUi/app/src/lib/ConfigurationPanel.svelte b/lib/SvelteUi/app/src/lib/ConfigurationPanel.svelte index f0a0c911..760616d4 100644 --- a/lib/SvelteUi/app/src/lib/ConfigurationPanel.svelte +++ b/lib/SvelteUi/app/src/lib/ConfigurationPanel.svelte @@ -68,8 +68,10 @@ getConfiguration(); let isFactoryReset = false; + let isFactoryResetComplete = false; async function factoryReset() { if(confirm("Are you sure you want to factory reset the device?")) { + isFactoryReset = true; const data = new URLSearchParams(); data.append("perform", "true"); const response = await fetch('/reset', { @@ -77,7 +79,8 @@ body: data }); let res = (await response.json()); - isFactoryReset = res.success; + isFactoryReset = false; + isFactoryResetComplete = res.success; } } @@ -764,4 +767,5 @@ - + + diff --git a/lib/SvelteUi/app/src/lib/Dashboard.svelte b/lib/SvelteUi/app/src/lib/Dashboard.svelte index 01a939fc..88aa6c4f 100644 --- a/lib/SvelteUi/app/src/lib/Dashboard.svelte +++ b/lib/SvelteUi/app/src/lib/Dashboard.svelte @@ -1,6 +1,6 @@ -
+
{#if uiVisibility(sysinfo.ui.i, data.i)} -
-
-
- +
+
+
+ +
+
{data.mt ? metertype(data.mt) : '-'}
+
{data.ic ? data.ic.toFixed(1) : '-'} kWh
-
{data.mt ? metertype(data.mt) : '-'}
-
{data.ic ? data.ic.toFixed(1) : '-'} kWh
-
{/if} {#if uiVisibility(sysinfo.ui.e, data.om || data.e > 0)}
- +
{data.ec ? data.ec.toFixed(1) : '-'} kWh
@@ -56,48 +56,48 @@
{/if} {#if uiVisibility(sysinfo.ui.v, data.u1 > 100 || data.u2 > 100 || data.u3 > 100)} -
- -
+
+ +
{/if} {#if uiVisibility(sysinfo.ui.a, data.i1 > 0.01 || data.i2 > 0.01 || data.i3 > 0.01)} -
- -
+
+ +
{/if} {#if uiVisibility(sysinfo.ui.r, data.ri > 0 || data.re > 0 || data.ric > 0 || data.rec > 0)} -
- -
+
+ +
{/if} {#if uiVisibility(sysinfo.ui.c, data.ea)} -
- -
+
+ 0 || data.e > 0}/> +
{/if} - {#if data && data.pr && (data.pr.startsWith("10YNO") || data.pr == '10Y1001A1001A48H')} -
- -
+ {#if uiVisibility(sysinfo.ui.t, data.pr && (data.pr.startsWith("10YNO") || data.pr == '10Y1001A1001A48H'))} +
+ +
{/if} {#if uiVisibility(sysinfo.ui.p, (typeof data.p == "number") && !Number.isNaN(data.p))} -
+
{/if} {#if uiVisibility(sysinfo.ui.d, dayPlot)} -
- -
+
+ +
{/if} {#if uiVisibility(sysinfo.ui.m, monthPlot)} -
- -
+
+ +
{/if} {#if uiVisibility(sysinfo.ui.s, data.t && data.t != -127 && temperatures.c > 1)} -
- -
+
+ +
{/if}
\ No newline at end of file diff --git a/lib/SvelteUi/app/src/lib/DataStores.js b/lib/SvelteUi/app/src/lib/DataStores.js index d664fc25..900f2ee3 100644 --- a/lib/SvelteUi/app/src/lib/DataStores.js +++ b/lib/SvelteUi/app/src/lib/DataStores.js @@ -25,7 +25,8 @@ let sysinfo = { booting: false, upgrading: false, ui: {}, - security: 0 + security: 0, + trying: null }; export const sysinfoStore = writable(sysinfo); export async function getSysinfo() { diff --git a/lib/SvelteUi/app/src/lib/Helpers.js b/lib/SvelteUi/app/src/lib/Helpers.js index e9580d05..ed96d4fc 100644 --- a/lib/SvelteUi/app/src/lib/Helpers.js +++ b/lib/SvelteUi/app/src/lib/Helpers.js @@ -15,6 +15,13 @@ export function ampcol(pct) { else return '#32d900'; }; +export function exportcol(pct) { + if(pct > 75) return '#32d900'; + else if(pct > 50) return '#77d900'; + else if(pct > 25) return '#94d900'; + else return '#dcd800'; +}; + export function metertype(mt) { switch(mt) { case 1: diff --git a/lib/SvelteUi/app/src/lib/PowerGauge.svelte b/lib/SvelteUi/app/src/lib/PowerGauge.svelte index 923139f3..121f6de8 100644 --- a/lib/SvelteUi/app/src/lib/PowerGauge.svelte +++ b/lib/SvelteUi/app/src/lib/PowerGauge.svelte @@ -1,6 +1,5 @@
- + {label}
diff --git a/lib/SvelteUi/app/src/lib/SetupPanel.svelte b/lib/SvelteUi/app/src/lib/SetupPanel.svelte index 0d9a4b39..6e5882fc 100644 --- a/lib/SvelteUi/app/src/lib/SetupPanel.svelte +++ b/lib/SvelteUi/app/src/lib/SetupPanel.svelte @@ -13,7 +13,15 @@ var url = ""; tries++; + var retry = function() { + setTimeout(scanForDevice, 1000); + }; + if(sysinfo.net.ip && tries%3 == 0) { + if(sysinfo.net.ip == '0.0.0.0') { + retry; + return; + }; url = "http://" + sysinfo.net.ip; } else if(sysinfo.hostname && tries%3 == 1) { url = "http://" + sysinfo.hostname; @@ -23,10 +31,10 @@ url = ""; } if(console) console.log("Trying url " + url); - - var retry = function() { - setTimeout(scanForDevice, 1000); - }; + sysinfoStore.update(s => { + s.trying = url; + return s; + }); var xhr = new XMLHttpRequest(); xhr.timeout = 5000; @@ -43,12 +51,10 @@ async function handleSubmit(e) { loadingOrSaving = true; const formData = new FormData(e.target); - let hostname = sysinfo.hostname; const data = new URLSearchParams(); for (let field of formData) { const [key, value] = field; data.append(key, value) - if(key == 'sh') hostname = value; } const response = await fetch('/save', { @@ -59,9 +65,15 @@ loadingOrSaving = false; sysinfoStore.update(s => { - s.hostname = hostname; + s.hostname = formData.get('sh'); s.usrcfg = res.success; s.booting = res.reboot; + if(staticIp) { + s.net.ip = formData.get('si'); + s.net.mask = formData.get('su'); + s.net.gw = formData.get('sg'); + s.net.dns1 = formData.get('sd'); + } setTimeout(scanForDevice, 5000); return s; }); @@ -76,7 +88,7 @@ Setup
SSID
- +
PSK
diff --git a/lib/SvelteUi/src/AmsWebServer.cpp b/lib/SvelteUi/src/AmsWebServer.cpp index 3a974f69..22b10869 100644 --- a/lib/SvelteUi/src/AmsWebServer.cpp +++ b/lib/SvelteUi/src/AmsWebServer.cpp @@ -407,7 +407,7 @@ void AmsWebServer::dataJson() { snprintf_P(buf, BufferSize, DATA_JSON, maxPwr == 0 ? meterState->isThreePhase() ? 20000 : 10000 : maxPwr, meterConfig->productionCapacity, - meterConfig->mainFuse == 0 ? 32 : meterConfig->mainFuse, + meterConfig->mainFuse == 0 ? 40 : meterConfig->mainFuse, meterState->getActiveImportPower(), meterState->getActiveExportPower(), meterState->getReactiveImportPower(), @@ -454,7 +454,7 @@ void AmsWebServer::dataJson() { ea->getCostThisMonth(), ea->getProducedThisMonth(), ea->getIncomeThisMonth(), - priceRegion.c_str(), + eapi == NULL ? "" : priceRegion.c_str(), meterState->getLastError(), eapi == NULL ? 0 : eapi->getLastError(), (uint32_t) now, diff --git a/src/AmsToMqttBridge.ino b/src/AmsToMqttBridge.ino index 9f72fa85..8b5997e3 100644 --- a/src/AmsToMqttBridge.ino +++ b/src/AmsToMqttBridge.ino @@ -599,7 +599,7 @@ void loop() { } try { if(meterState.getLastError() > 0) { - if(now - meterAutodetectLastChange > 15000 && (meterConfig.baud == 0 || meterConfig.parity == 0)) { + if(now - meterAutodetectLastChange > 20000 && (meterConfig.baud == 0 || meterConfig.parity == 0)) { meterAutodetect = true; meterAutoIndex++; // Default is to try the first one in setup() debugI("Meter serial autodetect, swapping to: %d, %d, %s", bauds[meterAutoIndex], parities[meterAutoIndex], inverts[meterAutoIndex] ? "true" : "false"); @@ -608,7 +608,6 @@ void loop() { meterAutodetectLastChange = now; } } else if(meterAutodetect) { - meterAutoIndex--; // Last one worked, so lets use that debugI("Meter serial autodetected, saving: %d, %d, %s", bauds[meterAutoIndex], parities[meterAutoIndex], inverts[meterAutoIndex] ? "true" : "false"); meterAutodetect = false; meterConfig.baud = bauds[meterAutoIndex];