move to central config, make TZ compile time const, confgureable later!
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
interface PlantConfig {
|
||||
ap_ssid: string,
|
||||
ssid: string,
|
||||
password: string,
|
||||
mqtt_url: string,
|
||||
base_topic: string,
|
||||
tank_sensor_enabled: boolean,
|
||||
@@ -24,12 +27,53 @@ interface PlantConfig {
|
||||
}[]
|
||||
}
|
||||
|
||||
interface SSIDList {
|
||||
ssids : [string]
|
||||
}
|
||||
|
||||
interface TestPump{
|
||||
pump: number
|
||||
}
|
||||
|
||||
let plants = document.getElementById("plants") as HTMLInputElement;
|
||||
|
||||
let scanWifiBtn = document.getElementById("scan") as HTMLButtonElement;
|
||||
if(scanWifiBtn){
|
||||
scanWifiBtn.onclick = scanWifi;
|
||||
}
|
||||
|
||||
export function scanWifi(){
|
||||
var scanButton = (document.getElementById("scan") as HTMLButtonElement);
|
||||
scanButton.disabled = true;
|
||||
|
||||
var ajax = new XMLHttpRequest();
|
||||
ajax.responseType = 'json';
|
||||
ajax.onreadystatechange = () => {
|
||||
if (ajax.readyState === 4) {
|
||||
callback(ajax.response);
|
||||
}
|
||||
};
|
||||
ajax.onerror = (evt) => {
|
||||
console.log(evt)
|
||||
scanButton.disabled = false;
|
||||
alert("Failed to start see console")
|
||||
}
|
||||
ajax.open("POST", "/wifiscan");
|
||||
ajax.send();
|
||||
}
|
||||
|
||||
function callback(data:SSIDList){
|
||||
var ssidlist = document.getElementById("ssidlist")
|
||||
ssidlist.innerHTML = ''
|
||||
|
||||
for (var ssid of data.ssids) {
|
||||
var wi = document.createElement("option");
|
||||
wi.value = ssid;
|
||||
ssidlist.appendChild(wi);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let fromWrapper = (() => {
|
||||
|
||||
let plantcount = 0;
|
||||
@@ -42,7 +86,12 @@ let fromWrapper = (() => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var ap_ssid = (document.getElementById("ap_ssid") as HTMLInputElement);
|
||||
ap_ssid.onchange = updateJson
|
||||
var ssid = (document.getElementById("ssid") as HTMLInputElement);
|
||||
ssid.onchange = updateJson
|
||||
var password = (document.getElementById("password") as HTMLInputElement);
|
||||
password.onchange = updateJson
|
||||
let mqtt_url = document.getElementById("mqtt_url") as HTMLInputElement;
|
||||
mqtt_url.onchange = updateJson
|
||||
let base_topic = document.getElementById("base_topic") as HTMLInputElement;
|
||||
@@ -235,6 +284,11 @@ let fromWrapper = (() => {
|
||||
|
||||
function sync(current: PlantConfig) {
|
||||
plantcount = current.plants.length
|
||||
|
||||
ap_ssid.value = current.ap_ssid;
|
||||
ssid.value = current.ssid;
|
||||
password.value = current.password;
|
||||
|
||||
mqtt_url.value = current.mqtt_url;
|
||||
base_topic.value = current.base_topic;
|
||||
max_consecutive_pump_count.value = current.max_consecutive_pump_count.toString();
|
||||
@@ -274,6 +328,9 @@ let fromWrapper = (() => {
|
||||
|
||||
function updateJson() {
|
||||
var current: PlantConfig = {
|
||||
ap_ssid: ap_ssid.value,
|
||||
ssid: ssid.value,
|
||||
password: password.value,
|
||||
max_consecutive_pump_count: +max_consecutive_pump_count.value,
|
||||
mqtt_url: mqtt_url.value,
|
||||
base_topic: base_topic.value,
|
||||
@@ -339,7 +396,12 @@ let fromWrapper = (() => {
|
||||
|
||||
fetch("/get_config")
|
||||
.then(response => response.json())
|
||||
.then(json => { createForm(json as PlantConfig); }
|
||||
.then(loaded => {
|
||||
var currentConfig = loaded as PlantConfig;
|
||||
createForm(currentConfig);
|
||||
var pretty = JSON.stringify(currentConfig, undefined, 1);
|
||||
json.value = pretty;
|
||||
}
|
||||
)
|
||||
})
|
||||
if (plants) {
|
||||
|
@@ -1,93 +0,0 @@
|
||||
interface WifiConfig {
|
||||
ssid: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
interface SSIDList {
|
||||
ssids : [string]
|
||||
}
|
||||
|
||||
export function saveWifi(){
|
||||
var saveButton = (document.getElementById("save") as HTMLButtonElement);
|
||||
saveButton.disabled = true;
|
||||
var ssid = (document.getElementById("ssid") as HTMLInputElement).value
|
||||
var password = (document.getElementById("password") as HTMLInputElement).value
|
||||
|
||||
var wifistatus = document.getElementById("wifistatus")
|
||||
|
||||
var wificonfig:WifiConfig = {ssid, password}
|
||||
var pretty = JSON.stringify(wificonfig, undefined, 4);
|
||||
console.log("Sending config " + pretty)
|
||||
|
||||
var ajax = new XMLHttpRequest();
|
||||
ajax.onreadystatechange = () => {
|
||||
wifistatus.innerText = ajax.responseText
|
||||
};
|
||||
ajax.onerror = (evt) => {
|
||||
console.log(evt)
|
||||
wifistatus.innerText = ajax.responseText
|
||||
saveButton.disabled = false;
|
||||
alert("Failed to save config see console")
|
||||
}
|
||||
ajax.open("POST", "/wifisave");
|
||||
ajax.send(pretty);
|
||||
}
|
||||
|
||||
export function scanWifi(){
|
||||
var scanButton = (document.getElementById("scan") as HTMLButtonElement);
|
||||
scanButton.disabled = true;
|
||||
|
||||
var ajax = new XMLHttpRequest();
|
||||
ajax.responseType = 'json';
|
||||
ajax.onreadystatechange = () => {
|
||||
if (ajax.readyState === 4) {
|
||||
callback(ajax.response);
|
||||
}
|
||||
};
|
||||
ajax.onerror = (evt) => {
|
||||
console.log(evt)
|
||||
scanButton.disabled = false;
|
||||
alert("Failed to start see console")
|
||||
}
|
||||
ajax.open("POST", "/wifiscan");
|
||||
ajax.send();
|
||||
}
|
||||
|
||||
function test(){
|
||||
var testButton = (document.getElementById("test") as HTMLButtonElement);
|
||||
testButton.disabled = true;
|
||||
|
||||
var ajax = new XMLHttpRequest();
|
||||
ajax.responseType = 'json';
|
||||
ajax.onerror = (evt) => {
|
||||
console.log(evt)
|
||||
testButton.disabled = false;
|
||||
alert("Failed to start see console")
|
||||
}
|
||||
ajax.open("POST", "/boardtest");
|
||||
ajax.send();
|
||||
}
|
||||
|
||||
function callback(data:SSIDList){
|
||||
var ssidlist = document.getElementById("ssidlist")
|
||||
ssidlist.innerHTML = ''
|
||||
|
||||
for (var ssid of data.ssids) {
|
||||
var wi = document.createElement("option");
|
||||
wi.value = ssid;
|
||||
ssidlist.appendChild(wi);
|
||||
}
|
||||
}
|
||||
|
||||
let testBtn = document.getElementById("test") as HTMLButtonElement;
|
||||
if(testBtn){
|
||||
testBtn.onclick = test;
|
||||
}
|
||||
let scanWifiBtn = document.getElementById("scan") as HTMLButtonElement;
|
||||
if(scanWifiBtn){
|
||||
scanWifiBtn.onclick = scanWifi;
|
||||
}
|
||||
let saveWifiBtn = document.getElementById("save") as HTMLButtonElement;
|
||||
if(saveWifiBtn){
|
||||
saveWifiBtn.onclick = saveWifi;
|
||||
}
|
@@ -3,7 +3,7 @@ const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
mode: "development",
|
||||
entry: ['./src/form.ts','./src/ota.ts','./src/wifi.ts', "./src/battery.ts"],
|
||||
entry: ['./src/form.ts','./src/ota.ts', "./src/battery.ts"],
|
||||
devtool: 'inline-source-map',
|
||||
module: {
|
||||
rules: [
|
||||
|
Reference in New Issue
Block a user