More v2.2

This commit is contained in:
Gunnar Skjold
2022-12-02 19:03:16 +01:00
parent 000cfd8697
commit 148fb14c93
31 changed files with 645 additions and 312 deletions

View File

@@ -31,7 +31,7 @@
<div class="container mx-auto m-3">
<Router>
<Header data={data} sysinfo={sysinfo}/>
<Header data={data}/>
<Route path="/">
<Dashboard data={data}/>
</Route>

View File

@@ -25,15 +25,15 @@
{#if hasExport}
<div class="flex">
<div>Hour</div>
<div class="flex-auto text-right">{data.h.p ? data.h.p.toFixed(2) : '-'} kWh {#if currency}/ {data.h.pc ? data.h.pc.toFixed(2) : '-'} {currency}{/if}</div>
<div class="flex-auto text-right">{data.h.p ? data.h.p.toFixed(2) : '-'} kWh {#if currency}/ {data.h.i ? data.h.i.toFixed(2) : '-'} {currency}{/if}</div>
</div>
<div class="flex">
<div>Day</div>
<div class="flex-auto text-right">{data.d.p ? data.d.p.toFixed(1) : '-'} kWh {#if currency}/ {data.d.pc ? data.d.pc.toFixed(2) : '-'} {currency}{/if}</div>
<div class="flex-auto text-right">{data.d.p ? data.d.p.toFixed(1) : '-'} kWh {#if currency}/ {data.d.i ? data.d.i.toFixed(2) : '-'} {currency}{/if}</div>
</div>
<div class="flex">
<div>Month</div>
<div class="flex-auto text-right">{data.m.p ? data.m.p.toFixed(0) : '-'} kWh {#if currency}/ {data.m.pc ? data.m.pc.toFixed(2) : '-'} {currency}{/if}</div>
<div class="flex-auto text-right">{data.m.p ? data.m.p.toFixed(0) : '-'} kWh {#if currency}/ {data.m.i ? data.m.i.toFixed(2) : '-'} {currency}{/if}</div>
</div>
{:else}
<div class="flex">

View File

@@ -36,7 +36,7 @@
<div class="cnt">
<form on:submit|preventDefault={handleSubmit}>
<div>
Below are some stuff we need to know
Various permissions we need to do stuff:
</div>
<hr/>
<div class="my-3">

View File

@@ -1,14 +1,17 @@
<script>
import Mask from "./Mask.svelte";
export let action;
export let title;
let uploading = false;
</script>
<div class="grid xl:grid-cols-4 lg:grid-cols-2 md:grid-cols-2">
<div class="cnt">
<strong>Upload {title}</strong>
<p class="mb-4">Select a suitable file and click upload</p>
<form action="{action}" enctype="multipart/form-data" method="post">
<form action="{action}" enctype="multipart/form-data" method="post" on:submit={() => uploading=true}>
<input name="file" type="file">
<div class="w-full text-right mt-4">
<button type="submit" class="btn-pri">Upload</button>
@@ -16,3 +19,4 @@
</form>
</div>
</div>
<Mask active={uploading} message="Uploading file, please wait"/>

View File

@@ -2,7 +2,7 @@
import { Link } from "svelte-navigator";
import { sysinfoStore, getGitHubReleases, gitHubReleaseStore } from './DataStores.js';
import { upgrade, getNextVersion } from './UpgradeHelper';
import { boardtype } from './Helpers.js';
import { boardtype, hanError, mqttError } from './Helpers.js';
import GitHubLogo from './../assets/github.svg';
import Uptime from "./Uptime.svelte";
import Badge from './Badge.svelte';
@@ -13,7 +13,7 @@
import DownloadIcon from "./DownloadIcon.svelte";
export let data = {}
export let sysinfo = {}
let sysinfo = {}
let nextVersion = {};
@@ -28,11 +28,16 @@
}
}
}
sysinfoStore.subscribe(update => {
sysinfo = update;
if(update.fwconsent === 1) {
getGitHubReleases();
}
});
gitHubReleaseStore.subscribe(releases => {
nextVersion = getNextVersion(sysinfo.version, releases);
});
getGitHubReleases();
</script>
<nav class="bg-violet-600 p-1 rounded-md mx-2">
@@ -47,13 +52,19 @@
{/if}
<div class="flex-none my-auto">Free mem: {data.m ? (data.m/1000).toFixed(1) : '-'}kb</div>
</div>
<div class="flex-auto my-auto justify-center p-2">
<div class="flex-auto flex-wrap my-auto justify-center p-2">
<Badge title="ESP" text={sysinfo.booting ? 'Booting' : data.v > 2.0 ? data.v.toFixed(2)+"V" : "ESP"} color={sysinfo.booting ? 'yellow' : data.em === 1 ? 'green' : data.em === 2 ? 'yellow' : data.em === 3 ? 'red' : 'gray'}/>
<Badge title="HAN" text="HAN" color={sysinfo.booting ? 'gray' : data.hm === 1 ? 'green' : data.hm === 2 ? 'yellow' : data.hm === 3 ? 'red' : 'gray'}/>
<Badge title="WiFi" text={data.r ? data.r.toFixed(0)+"dBm" : "WiFi"} color={sysinfo.booting ? 'gray' : data.wm === 1 ? 'green' : data.wm === 2 ? 'yellow' : data.wm === 3 ? 'red' : 'gray'}/>
<Badge title="MQTT" text="MQTT" color={sysinfo.booting ? 'gray' : data.mm === 1 ? 'green' : data.mm === 2 ? 'yellow' : data.mm === 3 ? 'red' : 'gray'}/>
</div>
<div class="flex-auto p-2 flex flex-row-reverse flex-wrap">
{#if data.he < 0}
<div class="bd-red">{ 'HAN error: ' + hanError(data.he) }</div>
{/if}
{#if data.me < 0}
<div class="bd-red">{ 'MQTT error: ' + mqttError(data.me) }</div>
{/if}
<div class="flex-auto p-2 flex flex-row-reverse flex-wrap">
<div class="flex-none">
<a class="float-right" href='https://github.com/gskjold/AmsToMqttBridge' target='_blank' rel="noreferrer" aria-label="GitHub"><img class="gh-logo" src={GitHubLogo} alt="GitHub repo"/></a>
</div>

View File

@@ -91,3 +91,33 @@ export function boardtype(c, b) {
return "Generic ESP8266";
}
}
export function hanError(err) {
switch(err) {
case -1: return "Parse error";
case -2: return "Incomplete data received";
case -3: return "Payload boundry flag missing";
case -4: return "Header checksum error";
case -5: return "Footer checksum error";
case -9: return "Unknown data received, check meter config";
case -41: return "Frame length not equal";
case -51: return "Authentication failed";
case -52: return "Decryption failed";
case -53: return "Encryption key invalid";
}
if(err < 0) return "Unspecified error "+err;
return "";
}
export function mqttError(err) {
switch(err) {
case -3: return "Connection failed";
case -4: return "Network timeout";
case -10: return "Connection denied";
case -11: return "Failed to subscribe";
case -13: return "Connection lost";
}
if(err < 0) return "Unspecified error "+err;
return "";
}

View File

@@ -4,6 +4,7 @@
import { upgrade, getNextVersion } from './UpgradeHelper';
import DownloadIcon from './DownloadIcon.svelte';
import { Link } from 'svelte-navigator';
import Mask from './Mask.svelte';
export let sysinfo;
@@ -45,6 +46,8 @@
}
let fileinput;
let files = [];
let uploading = false;
getSysinfo();
</script>
@@ -125,15 +128,16 @@
</div>
{/if}
<div class="my-2 flex">
<form action="/firmware" enctype="multipart/form-data" method="post">
<input style="display:none" name="file" type="file" accept=".bin" bind:this={fileinput}>
{#if fileinput && fileinput.files.length == 0}
<form action="/firmware" enctype="multipart/form-data" method="post" on:submit={() => uploading=true}>
<input style="display:none" name="file" type="file" accept=".bin" bind:this={fileinput} bind:files={files}>
{#if files.length == 0}
<button type="button" on:click={()=>{fileinput.click();}} class="text-xs py-1 px-2 rounded bg-blue-500 text-white float-right mr-3">Select firmware file for upgrade</button>
{:else if fileinput}
{fileinput.files[0].name}
{:else}
{files[0].name}
<button type="submit" class="ml-2 text-xs py-1 px-2 rounded bg-blue-500 text-white float-right mr-3">Upload</button>
{/if}
</form>
</div>
</div>
</div>
<Mask active={uploading} message="Uploading firmware, please wait"/>

View File

@@ -17,18 +17,17 @@ export default defineConfig({
plugins: [svelte()],
server: {
proxy: {
"/data.json": "http://192.168.233.244",
"/energyprice.json": "http://192.168.233.244",
"/dayplot.json": "http://192.168.233.244",
"/monthplot.json": "http://192.168.233.244",
"/temperature.json": "http://192.168.233.244",
"/sysinfo.json": "http://192.168.233.244",
"/configuration.json": "http://192.168.233.244",
"/tariff.json": "http://192.168.233.244",
"/save": "http://192.168.233.244",
"/reboot": "http://192.168.233.244",
"/firmware": "http://192.168.233.244",
"/upgrade": "http://192.168.233.244"
"/data.json": "http://192.168.233.229",
"/energyprice.json": "http://192.168.233.229",
"/dayplot.json": "http://192.168.233.229",
"/monthplot.json": "http://192.168.233.229",
"/temperature.json": "http://192.168.233.229",
"/sysinfo.json": "http://192.168.233.229",
"/configuration.json": "http://192.168.233.229",
"/tariff.json": "http://192.168.233.229",
"/save": "http://192.168.233.229",
"/reboot": "http://192.168.233.229",
"/upgrade": "http://192.168.233.229"
}
}
})