added solar ina handling, adjusted website

This commit is contained in:
2025-06-20 23:29:44 +02:00
parent 34b20b1f8f
commit 04849162cd
16 changed files with 301 additions and 42 deletions

View File

@@ -38,6 +38,12 @@ export interface FileList {
iter_error: string,
}
export interface SolarState{
mppt_voltage: number,
mppt_current: number,
is_day: boolean
}
export interface FileInfo{
filename: string,
size: number,

View File

@@ -13,7 +13,7 @@
<select class="boardvalue" id="hardware_board_value">
</select>
</div>
<div class="flexcontainer" style="text-decoration-line: line-through;">
<div class="flexcontainer">
<div class="boardkey">BatteryMonitor</div>
<select class="boardvalue" id="hardware_battery_value">
</select>

View File

@@ -149,6 +149,8 @@
</div>
<div id="batteryview" class="subcontainer">
</div>
<div id="solarview" class="subcontainer">
</div>
</div>
<div class="flexcontainer">

View File

@@ -28,8 +28,9 @@ import {
SetTime, SSIDList, TankInfo,
TestPump,
VersionInfo,
FileList
FileList, SolarState
} from "./api";
import {SolarView} from "./solarview";
export class Controller {
loadTankInfo() : Promise<void> {
@@ -160,7 +161,7 @@ export class Controller {
console.log(error);
});
}
updateBatteryData(): Promise<void> {
updateBatteryData() {
return fetch(PUBLIC_URL + "/battery")
.then(response => response.json())
.then(json => json as BatteryState)
@@ -172,6 +173,18 @@ export class Controller {
console.log(error);
})
}
updateSolarData() {
return fetch(PUBLIC_URL + "/solar")
.then(response => response.json())
.then(json => json as SolarState)
.then(solar => {
controller.solarView.update(solar)
})
.catch(error => {
controller.solarView.update(null)
console.log(error);
})
}
uploadNewFirmware(file: File) {
var current = 0;
var max = 100;
@@ -244,6 +257,7 @@ export class Controller {
//load from remote to be clean
controller.downloadConfig()
}
backupConfig(json: string, statusCallback: (status: string) => void) {
controller.progressview.addIndeterminate("backup_config", "Backingup Config")
fetch(PUBLIC_URL + "/backup_config", {
@@ -465,6 +479,7 @@ export class Controller {
readonly firmWareView: OTAView;
readonly progressview: ProgressView;
readonly batteryView: BatteryView;
readonly solarView: SolarView;
readonly fileview: FileView;
readonly logView: LogView
constructor() {
@@ -473,6 +488,7 @@ export class Controller {
this.networkView = new NetworkConfigView(this, PUBLIC_URL)
this.tankView = new TankConfigView(this)
this.batteryView = new BatteryView(this)
this.solarView = new SolarView(this)
this.nightLampView = new NightLampView(this)
this.submitView = new SubmitView(this)
this.firmWareView = new OTAView(this)
@@ -489,21 +505,16 @@ export class Controller {
controller.exit();
}
}
selftest() {
}
}
const controller = new Controller();
controller.progressview.removeProgress("rebooting");
const tasks = [
{ task: controller.populateTimezones, displayString: "Populating Timezones" },
{ task: controller.updateRTCData, displayString: "Updating RTC Data" },
{ task: controller.updateBatteryData, displayString: "Updating Battery Data" },
{ task: controller.updateSolarData, displayString: "Updating Solar Data" },
{ task: controller.downloadConfig, displayString: "Downloading Configuration" },
{ task: controller.version, displayString: "Fetching Version Information" },
{ task: controller.updateFileList, displayString: "Updating File List" },

View File

@@ -20,7 +20,7 @@
<div class="lightkey">Test Nightlight</div>
<input class="lightcheckbox" type="checkbox" id="night_lamp_test">
</div>
<div class="flexcontainer" style="text-decoration-line: line-through;">
<div class="flexcontainer">
<div class="lightkey">Enable Nightlight</div>
<input class="lightcheckbox" type="checkbox" id="night_lamp_enabled">
</div>

View File

@@ -29,7 +29,7 @@ export class OTAView {
};
test.onclick = () => {
controller.selftest();
controller.selfTest();
}
}

View File

@@ -0,0 +1,29 @@
<style>
.solarflexkey {
min-width: 150px;
}
.solarflexvalue {
text-wrap: nowrap;
flex-grow: 1;
}
</style>
<div class="flexcontainer">
<div class="subtitle">
Mppt:
</div>
<input id="solar_auto_refresh" type="checkbox">
</div>
<div class="flexcontainer">
<span class="solarflexkey">Mppt mV:</span>
<span class="solarflexvalue" id="solar_voltage_milli_volt"></span>
</div>
<div class="flexcontainer">
<span class="solarflexkey">Mppt mA:</span>
<span class="solarflexvalue" id="solar_current_milli_ampere" ></span>
</div>
<div class="flexcontainer">
<span class="solarflexkey">is Day:</span>
<span class="solarflexvalue" id="solar_is_day" ></span>
</div>

View File

@@ -0,0 +1,49 @@
import { Controller } from "./main";
import {BatteryState, SolarState} from "./api";
export class SolarView{
solar_voltage_milli_volt: HTMLSpanElement;
solar_current_milli_ampere: HTMLSpanElement;
solar_is_day: HTMLSpanElement;
solar_auto_refresh: HTMLInputElement;
timer: NodeJS.Timeout | undefined;
controller: Controller;
constructor (controller:Controller) {
(document.getElementById("solarview") as HTMLElement).innerHTML = require("./solarview.html")
this.solar_voltage_milli_volt = document.getElementById("solar_voltage_milli_volt") as HTMLSpanElement;
this.solar_current_milli_ampere = document.getElementById("solar_current_milli_ampere") as HTMLSpanElement;
this.solar_is_day = document.getElementById("solar_is_day") as HTMLSpanElement;
this.solar_auto_refresh = document.getElementById("solar_auto_refresh") as HTMLInputElement;
this.controller = controller
this.solar_auto_refresh.onchange = () => {
if(this.timer){
clearTimeout(this.timer)
}
if(this.solar_auto_refresh.checked){
controller.updateSolarData()
}
}
}
update(solarState: SolarState|null){
if (solarState == null) {
this.solar_voltage_milli_volt.innerText = "N/A"
this.solar_current_milli_ampere.innerText = "N/A"
this.solar_is_day.innerText = "N/A"
} else {
this.solar_voltage_milli_volt.innerText = solarState.mppt_voltage.toFixed(2)
this.solar_current_milli_ampere.innerText = String(+solarState.mppt_current)
this.solar_is_day.innerText = solarState.is_day?"🌞":"🌙"
}
if(this.solar_auto_refresh.checked){
this.timer = setTimeout(this.controller.updateSolarData, 1000);
} else {
if(this.timer){
clearTimeout(this.timer)
}
}
}
}

View File

@@ -7,14 +7,31 @@
word-wrap: break-word;
overflow: scroll;
}
.submitbutton{
padding: 1em 1em;
background: #667eea;
color: white;
border: none;
border-radius: 8px;
font-size: 1.1em;
font-weight: bold;
cursor: pointer;
transition: all 0.3s ease;
letter-spacing: 1px;
margin: 1em 0;
}
.submitbutton:hover {
background: #1c4e63;
}
</style>
<button class="submitbutton" id="submit">Submit</button>
<br>
<button id="showJson">Show Json</button>
<div id="rawdata" class="flexcontainer" style="display: none;">
<div class="submitarea" id="json" contenteditable="true"></div>
<div class="submitarea" id="backupjson">backup will be here</div>
</div>
<button id="submit">Submit</button>
<div>BackupStatus:</div>
<div id="backuptimestamp"></div>
<div id="backupsize"></div>

View File

@@ -9,7 +9,7 @@ console.log("Dev server is " + isDevServer);
var host;
if (isDevServer){
//ensure no trailing /
host = 'http://192.168.71.1';
host = 'http://10.23.44.186';
} else {
host = '';
}