website update version display and ota handler
This commit is contained in:
@@ -157,7 +157,13 @@ export interface Moistures {
|
|||||||
export interface VersionInfo {
|
export interface VersionInfo {
|
||||||
git_hash: string,
|
git_hash: string,
|
||||||
build_time: string,
|
build_time: string,
|
||||||
partition: string
|
current: string,
|
||||||
|
slot0_state: string,
|
||||||
|
slot1_state: string,
|
||||||
|
heap_total: number,
|
||||||
|
heap_used: number,
|
||||||
|
heap_free: number,
|
||||||
|
heap_max_used: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BatteryState {
|
export interface BatteryState {
|
||||||
|
|||||||
@@ -201,15 +201,22 @@ export class Controller {
|
|||||||
}, false);
|
}, false);
|
||||||
ajax.addEventListener("load", () => {
|
ajax.addEventListener("load", () => {
|
||||||
controller.progressview.removeProgress("ota_upload")
|
controller.progressview.removeProgress("ota_upload")
|
||||||
|
const status = ajax.status;
|
||||||
|
if (status >= 200 && status < 300) {
|
||||||
controller.reboot();
|
controller.reboot();
|
||||||
|
} else {
|
||||||
|
const statusText = ajax.statusText || "";
|
||||||
|
const body = ajax.responseText || "";
|
||||||
|
toast.error(`OTA update error (${status}${statusText ? ' ' + statusText : ''}): ${body}`);
|
||||||
|
}
|
||||||
}, false);
|
}, false);
|
||||||
ajax.addEventListener("error", () => {
|
ajax.addEventListener("error", () => {
|
||||||
alert("Error ota")
|
|
||||||
controller.progressview.removeProgress("ota_upload")
|
controller.progressview.removeProgress("ota_upload")
|
||||||
|
toast.error("OTA upload failed due to a network error.");
|
||||||
}, false);
|
}, false);
|
||||||
ajax.addEventListener("abort", () => {
|
ajax.addEventListener("abort", () => {
|
||||||
alert("abort ota")
|
|
||||||
controller.progressview.removeProgress("ota_upload")
|
controller.progressview.removeProgress("ota_upload")
|
||||||
|
toast.error("OTA upload was aborted.");
|
||||||
}, false);
|
}, false);
|
||||||
ajax.open("POST", PUBLIC_URL + "/ota");
|
ajax.open("POST", PUBLIC_URL + "/ota");
|
||||||
ajax.send(file);
|
ajax.send(file);
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
<style>
|
<style>
|
||||||
.otakey{
|
.otakey {
|
||||||
min-width: 100px;
|
min-width: 100px;
|
||||||
}
|
}
|
||||||
.otavalue{
|
|
||||||
|
.otavalue {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.otaform {
|
.otaform {
|
||||||
min-width: 100px;
|
min-width: 100px;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.otachooser {
|
.otachooser {
|
||||||
min-width: 100px;
|
min-width: 100px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -18,6 +21,7 @@
|
|||||||
<div class="subtitle">
|
<div class="subtitle">
|
||||||
Current Firmware
|
Current Firmware
|
||||||
</div>
|
</div>
|
||||||
|
<button style="margin-left: auto;" type="button" id="refresh_firmware_info">Refresh</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="flexcontainer">
|
<div class="flexcontainer">
|
||||||
<span class="otakey">Buildtime:</span>
|
<span class="otakey">Buildtime:</span>
|
||||||
@@ -31,11 +35,43 @@
|
|||||||
<span class="otakey">Partition:</span>
|
<span class="otakey">Partition:</span>
|
||||||
<span class="otavalue" id="firmware_partition"></span>
|
<span class="otavalue" id="firmware_partition"></span>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flexcontainer">
|
||||||
|
<span class="otakey">State0:</span>
|
||||||
|
<span class="otavalue" id="firmware_state0"></span>
|
||||||
|
</div>
|
||||||
|
<div class="flexcontainer">
|
||||||
|
<span class="otakey">State1:</span>
|
||||||
|
<span class="otavalue" id="firmware_state1"></span>
|
||||||
|
</div>
|
||||||
<div class="flexcontainer">
|
<div class="flexcontainer">
|
||||||
<form class="otaform" id="upload_form" method="post">
|
<form class="otaform" id="upload_form" method="post">
|
||||||
<input class="otachooser" type="file" name="file1" id="firmware_file"><br>
|
<input class="otachooser" type="file" name="file1" id="firmware_file"><br>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flexcontainer">
|
||||||
|
<div class="subtitle">
|
||||||
|
Heap Memory
|
||||||
|
</div>
|
||||||
|
<div></div>
|
||||||
|
</div>
|
||||||
|
<div class="flexcontainer">
|
||||||
|
<span class="otakey">Free:</span>
|
||||||
|
<span class="otavalue" id="heap_free"></span>
|
||||||
|
</div>
|
||||||
|
<div class="flexcontainer">
|
||||||
|
<span class="otakey">Used:</span>
|
||||||
|
<span class="otavalue" id="heap_used"></span>
|
||||||
|
</div>
|
||||||
|
<div class="flexcontainer">
|
||||||
|
<span class="otakey">Total:</span>
|
||||||
|
<span class="otavalue" id="heap_total"></span>
|
||||||
|
</div>
|
||||||
|
<div class="flexcontainer">
|
||||||
|
<span class="otakey">Peak used:</span>
|
||||||
|
<span class="otavalue" id="heap_max_used"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="display:flex">
|
<div class="display:flex">
|
||||||
<button style="margin-left: 16px; margin-top: 8px;" class="col-6" type="button" id="test">Self-Test</button>
|
<button style="margin-left: 16px; margin-top: 8px;" class="col-6" type="button" id="test">Self-Test</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -1,21 +1,37 @@
|
|||||||
import { Controller } from "./main";
|
import {Controller} from "./main";
|
||||||
import {VersionInfo} from "./api";
|
import {VersionInfo} from "./api";
|
||||||
|
|
||||||
|
function fmtBytes(n: number): string {
|
||||||
|
return `${n} B (${(n / 1024).toFixed(1)} KiB)`;
|
||||||
|
}
|
||||||
|
|
||||||
export class OTAView {
|
export class OTAView {
|
||||||
readonly file1Upload: HTMLInputElement;
|
readonly file1Upload: HTMLInputElement;
|
||||||
readonly firmware_buildtime: HTMLDivElement;
|
readonly firmware_buildtime: HTMLDivElement;
|
||||||
readonly firmware_githash: HTMLDivElement;
|
readonly firmware_githash: HTMLDivElement;
|
||||||
readonly firmware_partition: HTMLDivElement;
|
readonly firmware_partition: HTMLDivElement;
|
||||||
|
readonly firmware_state0: HTMLDivElement;
|
||||||
|
readonly firmware_state1: HTMLDivElement;
|
||||||
|
readonly heap_free: HTMLDivElement;
|
||||||
|
readonly heap_used: HTMLDivElement;
|
||||||
|
readonly heap_total: HTMLDivElement;
|
||||||
|
readonly heap_max_used: HTMLDivElement;
|
||||||
|
|
||||||
constructor(controller: Controller) {
|
constructor(controller: Controller) {
|
||||||
(document.getElementById("firmwareview") as HTMLElement).innerHTML = require("./ota.html")
|
(document.getElementById("firmwareview") as HTMLElement).innerHTML = require("./ota.html")
|
||||||
|
|
||||||
let test = document.getElementById("test") as HTMLButtonElement;
|
let test = document.getElementById("test") as HTMLButtonElement;
|
||||||
|
let refresh = document.getElementById("refresh_firmware_info") as HTMLButtonElement;
|
||||||
|
|
||||||
this.firmware_buildtime = document.getElementById("firmware_buildtime") as HTMLDivElement;
|
this.firmware_buildtime = document.getElementById("firmware_buildtime") as HTMLDivElement;
|
||||||
this.firmware_githash = document.getElementById("firmware_githash") as HTMLDivElement;
|
this.firmware_githash = document.getElementById("firmware_githash") as HTMLDivElement;
|
||||||
this.firmware_partition = document.getElementById("firmware_partition") as HTMLDivElement;
|
this.firmware_partition = document.getElementById("firmware_partition") as HTMLDivElement;
|
||||||
|
this.firmware_state0 = document.getElementById("firmware_state0") as HTMLDivElement;
|
||||||
|
this.firmware_state1 = document.getElementById("firmware_state1") as HTMLDivElement;
|
||||||
|
this.heap_free = document.getElementById("heap_free") as HTMLDivElement;
|
||||||
|
this.heap_used = document.getElementById("heap_used") as HTMLDivElement;
|
||||||
|
this.heap_total = document.getElementById("heap_total") as HTMLDivElement;
|
||||||
|
this.heap_max_used = document.getElementById("heap_max_used") as HTMLDivElement;
|
||||||
|
|
||||||
const file = document.getElementById("firmware_file") as HTMLInputElement;
|
const file = document.getElementById("firmware_file") as HTMLInputElement;
|
||||||
this.file1Upload = file
|
this.file1Upload = file
|
||||||
@@ -31,11 +47,21 @@ export class OTAView {
|
|||||||
test.onclick = () => {
|
test.onclick = () => {
|
||||||
controller.selfTest();
|
controller.selfTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refresh.onclick = () => {
|
||||||
|
controller.version();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setVersion(versionInfo: VersionInfo) {
|
setVersion(versionInfo: VersionInfo) {
|
||||||
this.firmware_buildtime.innerText = versionInfo.build_time;
|
this.firmware_buildtime.innerText = versionInfo.build_time;
|
||||||
this.firmware_githash.innerText = versionInfo.git_hash;
|
this.firmware_githash.innerText = versionInfo.git_hash;
|
||||||
this.firmware_partition.innerText = versionInfo.partition;
|
this.firmware_partition.innerText = versionInfo.current;
|
||||||
|
this.firmware_state0.innerText = versionInfo.slot0_state;
|
||||||
|
this.firmware_state1.innerText = versionInfo.slot1_state;
|
||||||
|
this.heap_free.innerText = fmtBytes(versionInfo.heap_free);
|
||||||
|
this.heap_used.innerText = fmtBytes(versionInfo.heap_used);
|
||||||
|
this.heap_total.innerText = fmtBytes(versionInfo.heap_total);
|
||||||
|
this.heap_max_used.innerText = fmtBytes(versionInfo.heap_max_used);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user