Compare commits
No commits in common. "8ff2763580a831a2c641626c4c7bcd7df9e960ff" and "53bd1f8ccedd8e06454b4795ad88c62ecd881901" have entirely different histories.
8ff2763580
...
53bd1f8cce
@ -32,7 +32,7 @@ use tank::*;
|
|||||||
|
|
||||||
const TIME_ZONE: Tz = Berlin;
|
const TIME_ZONE: Tz = Berlin;
|
||||||
|
|
||||||
const MOIST_SENSOR_MAX_FREQUENCY: u32 = 5500; // 60kHz (500Hz margin)
|
const MOIST_SENSOR_MAX_FREQUENCY: u32 = 5000; // 60kHz (500Hz margin)
|
||||||
const MOIST_SENSOR_MIN_FREQUENCY: u32 = 150; // this is really really dry, think like cactus levels
|
const MOIST_SENSOR_MIN_FREQUENCY: u32 = 150; // this is really really dry, think like cactus levels
|
||||||
|
|
||||||
const FROM: (f32, f32) = (
|
const FROM: (f32, f32) = (
|
||||||
|
@ -188,14 +188,7 @@ fn backup_info(
|
|||||||
};
|
};
|
||||||
serde_json::to_string(&wbh)?
|
serde_json::to_string(&wbh)?
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => "{\"error\":\"Header could not be parsed\"".to_owned(),
|
||||||
//TODO make better
|
|
||||||
let wbh = WebBackupHeader {
|
|
||||||
timestamp: "no backup".to_owned(),
|
|
||||||
size: 0,
|
|
||||||
};
|
|
||||||
serde_json::to_string(&wbh)?
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
anyhow::Ok(Some(json))
|
anyhow::Ok(Some(json))
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,3 @@
|
|||||||
interface LogArray extends Array<LogEntry>{}
|
|
||||||
|
|
||||||
interface LogEntry {
|
|
||||||
timestamp: string,
|
|
||||||
message_id: number,
|
|
||||||
a: number,
|
|
||||||
b: number,
|
|
||||||
txt_short: string,
|
|
||||||
txt_long: string
|
|
||||||
}
|
|
||||||
|
|
||||||
interface LogLocalisation extends Array<LogLocalisationEntry>{}
|
|
||||||
|
|
||||||
interface LogLocalisationEntry {
|
|
||||||
msg_type: string,
|
|
||||||
message: string
|
|
||||||
}
|
|
||||||
|
|
||||||
interface BackupHeader {
|
interface BackupHeader {
|
||||||
timestamp: string,
|
timestamp: string,
|
||||||
size: number
|
size: number
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
<style>
|
|
||||||
|
|
||||||
</style>
|
|
||||||
<button id="loadLog">Load Logs</button>
|
|
||||||
<div id="logpanel">
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,47 +0,0 @@
|
|||||||
import { Controller } from "./main";
|
|
||||||
|
|
||||||
export class LogView {
|
|
||||||
private readonly logpanel: HTMLElement;
|
|
||||||
private readonly loadLog: HTMLButtonElement;
|
|
||||||
loglocale: LogLocalisation | undefined;
|
|
||||||
|
|
||||||
constructor(controller: Controller) {
|
|
||||||
(document.getElementById("logview") as HTMLElement).innerHTML = require('./log.html') as string;
|
|
||||||
this.logpanel = document.getElementById("logpanel") as HTMLElement
|
|
||||||
this.loadLog = document.getElementById("loadLog") as HTMLButtonElement
|
|
||||||
|
|
||||||
controller.loadLogLocaleConfig();
|
|
||||||
|
|
||||||
this.loadLog.onclick = () => {
|
|
||||||
controller.loadLog();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setLogLocalisation(loglocale: LogLocalisation) {
|
|
||||||
this.loglocale = loglocale;
|
|
||||||
}
|
|
||||||
|
|
||||||
setLog(logs: LogArray) {
|
|
||||||
this.logpanel.textContent = ""
|
|
||||||
logs.forEach(entry => {
|
|
||||||
let message = this.loglocale!![entry.message_id];
|
|
||||||
let template = message.message
|
|
||||||
template = template.replace("${number_a}", entry.a.toString());
|
|
||||||
template = template.replace("${number_b}", entry.b.toString());
|
|
||||||
template = template.replace("${txt_short}", entry.txt_short.toString());
|
|
||||||
template = template.replace("${txt_long}", entry.txt_long.toString());
|
|
||||||
|
|
||||||
let ts = new Date(entry.timestamp);
|
|
||||||
|
|
||||||
let div = document.createElement("div")
|
|
||||||
let timestampDiv = document.createElement("div")
|
|
||||||
let messageDiv = document.createElement("div")
|
|
||||||
timestampDiv.innerText = ts.toISOString();
|
|
||||||
messageDiv.innerText = template;
|
|
||||||
div.appendChild(timestampDiv)
|
|
||||||
div.appendChild(messageDiv)
|
|
||||||
this.logpanel.appendChild(div)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
@ -171,10 +171,6 @@
|
|||||||
<button id="exit">Exit</button>
|
<button id="exit">Exit</button>
|
||||||
<button id="reboot">Reboot</button>
|
<button id="reboot">Reboot</button>
|
||||||
|
|
||||||
<div class="flexcontainer">
|
|
||||||
<div id="logview" class="subcontainercontainer"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="bundle.js"></script>
|
<script src="bundle.js"></script>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -17,33 +17,10 @@ import { ProgressView } from "./progress";
|
|||||||
import { OTAView } from "./ota";
|
import { OTAView } from "./ota";
|
||||||
import { BatteryView } from "./batteryview";
|
import { BatteryView } from "./batteryview";
|
||||||
import { FileView } from './fileview';
|
import { FileView } from './fileview';
|
||||||
import { LogView } from './log';
|
|
||||||
|
|
||||||
export class Controller {
|
export class Controller {
|
||||||
loadLogLocaleConfig() {
|
getBackupInfo() {
|
||||||
return fetch(PUBLIC_URL + "/log_localization")
|
fetch(PUBLIC_URL + "/backup_info")
|
||||||
.then(response => response.json())
|
|
||||||
.then(json => json as LogLocalisation)
|
|
||||||
.then(loglocale => {
|
|
||||||
controller.logView.setLogLocalisation(loglocale)
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
loadLog() {
|
|
||||||
return fetch(PUBLIC_URL + "/log")
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(json => json as LogArray)
|
|
||||||
.then(logs => {
|
|
||||||
controller.logView.setLog(logs)
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
getBackupInfo() : Promise<void> {
|
|
||||||
return fetch(PUBLIC_URL + "/backup_info")
|
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => json as BackupHeader)
|
.then(json => json as BackupHeader)
|
||||||
.then(header => {
|
.then(header => {
|
||||||
@ -53,8 +30,8 @@ export class Controller {
|
|||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
updateFileList() : Promise<void> {
|
updateFileList() {
|
||||||
return fetch(PUBLIC_URL + "/files")
|
fetch(PUBLIC_URL + "/files")
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => json as FileList)
|
.then(json => json as FileList)
|
||||||
.then(filelist => {
|
.then(filelist => {
|
||||||
@ -113,8 +90,8 @@ export class Controller {
|
|||||||
controller.updateFileList()
|
controller.updateFileList()
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRTCData() : Promise<void> {
|
updateRTCData() {
|
||||||
return fetch(PUBLIC_URL + "/time")
|
fetch(PUBLIC_URL + "/time")
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => json as GetTime)
|
.then(json => json as GetTime)
|
||||||
.then(time => {
|
.then(time => {
|
||||||
@ -125,8 +102,8 @@ export class Controller {
|
|||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
updateBatteryData(): Promise<void> {
|
updateBatteryData() {
|
||||||
return fetch(PUBLIC_URL + "/battery")
|
fetch(PUBLIC_URL + "/battery")
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => json as BatteryState)
|
.then(json => json as BatteryState)
|
||||||
.then(battery => {
|
.then(battery => {
|
||||||
@ -135,7 +112,7 @@ export class Controller {
|
|||||||
.catch(error => {
|
.catch(error => {
|
||||||
controller.batteryView.update(null)
|
controller.batteryView.update(null)
|
||||||
console.log(error);
|
console.log(error);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
uploadNewFirmware(file: File) {
|
uploadNewFirmware(file: File) {
|
||||||
var current = 0;
|
var current = 0;
|
||||||
@ -162,9 +139,9 @@ export class Controller {
|
|||||||
ajax.open("POST", PUBLIC_URL + "/ota");
|
ajax.open("POST", PUBLIC_URL + "/ota");
|
||||||
ajax.send(file);
|
ajax.send(file);
|
||||||
}
|
}
|
||||||
version() : Promise<void> {
|
version() {
|
||||||
controller.progressview.addIndeterminate("version", "Getting buildVersion")
|
controller.progressview.addIndeterminate("version", "Getting buildVersion")
|
||||||
return fetch(PUBLIC_URL + "/version")
|
fetch(PUBLIC_URL + "/version")
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => json as VersionInfo)
|
.then(json => json as VersionInfo)
|
||||||
.then(versionInfo => {
|
.then(versionInfo => {
|
||||||
@ -183,9 +160,9 @@ export class Controller {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadConfig() :Promise<void> {
|
downloadConfig() {
|
||||||
controller.progressview.addIndeterminate("get_config", "Downloading Config")
|
controller.progressview.addIndeterminate("get_config", "Downloading Config")
|
||||||
return fetch(PUBLIC_URL + "/get_config")
|
fetch(PUBLIC_URL + "/get_config")
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(loaded => {
|
.then(loaded => {
|
||||||
var currentConfig = loaded as PlantControllerConfig;
|
var currentConfig = loaded as PlantControllerConfig;
|
||||||
@ -422,7 +399,6 @@ export class Controller {
|
|||||||
readonly progressview: ProgressView;
|
readonly progressview: ProgressView;
|
||||||
readonly batteryView: BatteryView;
|
readonly batteryView: BatteryView;
|
||||||
readonly fileview: FileView;
|
readonly fileview: FileView;
|
||||||
readonly logView: LogView
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.timeView = new TimeView(this)
|
this.timeView = new TimeView(this)
|
||||||
this.plantViews = new PlantViews(this)
|
this.plantViews = new PlantViews(this)
|
||||||
@ -434,7 +410,6 @@ export class Controller {
|
|||||||
this.firmWareView = new OTAView(this)
|
this.firmWareView = new OTAView(this)
|
||||||
this.progressview = new ProgressView(this)
|
this.progressview = new ProgressView(this)
|
||||||
this.fileview = new FileView(this)
|
this.fileview = new FileView(this)
|
||||||
this.logView = new LogView(this)
|
|
||||||
this.rebootBtn = document.getElementById("reboot") as HTMLButtonElement
|
this.rebootBtn = document.getElementById("reboot") as HTMLButtonElement
|
||||||
this.rebootBtn.onclick = () => {
|
this.rebootBtn.onclick = () => {
|
||||||
controller.reboot();
|
controller.reboot();
|
||||||
@ -446,31 +421,12 @@ export class Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const controller = new Controller();
|
const controller = new Controller();
|
||||||
controller.progressview.removeProgress("rebooting");
|
controller.updateRTCData();
|
||||||
controller.progressview.addProgress("initial", 0, "read rtc");
|
controller.updateBatteryData();
|
||||||
controller.updateRTCData().then(_ => {
|
controller.downloadConfig();
|
||||||
controller.progressview.addProgress("initial", 20, "read battery");
|
|
||||||
controller.updateBatteryData().then(_ => {
|
|
||||||
controller.progressview.addProgress("initial", 40, "read config");
|
|
||||||
controller.downloadConfig().then(_ => {
|
|
||||||
controller.progressview.addProgress("initial", 50, "read version");
|
|
||||||
controller.version().then(_ => {
|
|
||||||
controller.progressview.addProgress("initial", 70, "read filelist");
|
|
||||||
controller.updateFileList().then(_ => {
|
|
||||||
controller.progressview.addProgress("initial", 90, "read backupinfo");
|
|
||||||
controller.getBackupInfo().then(_ => {
|
|
||||||
controller.progressview.removeProgress("initial");
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
});
|
|
||||||
})
|
|
||||||
})
|
|
||||||
;
|
|
||||||
|
|
||||||
//controller.measure_moisture();
|
//controller.measure_moisture();
|
||||||
|
controller.version();
|
||||||
|
controller.updateFileList();
|
||||||
|
controller.getBackupInfo();
|
||||||
controller.progressview.removeProgress("rebooting");
|
controller.progressview.removeProgress("rebooting");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user