diff --git a/dev/admin.htm b/dev/admin.htm
index 3dc024f..2ef3c8b 100644
--- a/dev/admin.htm
+++ b/dev/admin.htm
@@ -6,14 +6,13 @@ function status(msg) {
document.getElementById('status').textContent = msg
}
async function queryParams() {
- const req = await fetch('/api/params')
- const json = await req.json()
+ const resp = await fetch('/api/params')
//console.log(json)
//console.log(Object.keys(json))
- if (!req.ok) {
+ if (!resp.ok) {
var err_msg = null
- if (req.body != null) {
- err_msg = await req.text()
+ if (resp.body != null) {
+ err_msg = await resp.text()
}
if (err_msg != null) {
status("query failed: " + resp.status + " " + err_msg)
@@ -21,6 +20,7 @@ async function queryParams() {
status("query failed: " + resp.status)
}
}
+ const json = await resp.json()
status('parameter query successful!')
const paramList = document.getElementById('param-list')
while (paramList.firstChild) {
@@ -43,12 +43,10 @@ async function setParam(auth, name, value) {
}
}
})
- console.log('set param fetch pre')
const resp = await fetch('/api/admin', {
method: 'POST',
body: msg
})
- console.log('set param fetch post')
if (!resp.ok) {
var err_msg = null
if (resp.body != null) {
@@ -65,6 +63,78 @@ async function setParam(auth, name, value) {
}
}
+var manual_mode = false
+var manual_loop_running = false
+const sleep = (ms) => new Promise(r => setTimeout(r, ms))
+async function manualModeLoop(auth) {
+ if (manual_loop_running) return
+ manual_loop_running = true
+ try {
+ while (manual_mode) {
+ await sleep(60*1000)
+ if (manual_mode) await manualMode(auth, manual_mode)
+ }
+ } finally {
+ manual_loop_running = false
+ }
+}
+async function manualMode(auth, on) {
+ const msg = JSON.stringify({
+ auth: auth,
+ data: {
+ manual_mode: on
+ }
+ })
+ const resp = await fetch('/api/admin', {
+ method: 'POST',
+ body: msg
+ })
+ if (!resp.ok) {
+ var err_msg = null
+ if (resp.body != null) {
+ err_msg = await resp.text()
+ }
+ if (err_msg != null) {
+ status("manual mode set failed: " + resp.status + " " + err_msg)
+ } else {
+ status("manual mode set failed: " + resp.status)
+ }
+ } else {
+ status("manual mode set successful!")
+ manual_mode = on
+ if (manual_mode) {
+ manualModeLoop(auth)
+ }
+ //await queryParams()
+ }
+}
+
+async function manualHumidifier(auth, on) {
+ const msg = JSON.stringify({
+ auth: auth,
+ data: {
+ manual_mode_on: on
+ }
+ })
+ const resp = await fetch('/api/admin', {
+ method: 'POST',
+ body: msg
+ })
+ if (!resp.ok) {
+ var err_msg = null
+ if (resp.body != null) {
+ err_msg = await resp.text()
+ }
+ if (err_msg != null) {
+ status("manual hum set failed: " + resp.status + " " + err_msg)
+ } else {
+ status("manual hum set failed: " + resp.status)
+ }
+ } else {
+ status("manual hum set successful!")
+ }
+}
+
window.onload = () => {
document.getElementById('query-params').addEventListener('click', (e) => {
queryParams()
@@ -80,6 +150,17 @@ window.onload = () => {
}
setParam(auth, name, value)
})
+
+ document.getElementById('manual-mode').addEventListener('click', (e) => {
+ const auth = document.getElementById('password').value
+ const on = document.getElementById('manual-mode').checked
+ manualMode(auth, on)
+ })
+ document.getElementById('manual-on').addEventListener('click', (e) => {
+ const auth = document.getElementById('password').value
+ const on = document.getElementById('manual-on').checked
+ manualHumidifier(auth, on)
+ })
}
@@ -104,6 +185,11 @@ window.onload = () => {
+