From d24f0b9432dbf7e6c576b9b1e872a4860ba46425 Mon Sep 17 00:00:00 2001 From: 00asdf Date: Fri, 25 Apr 2025 18:10:09 +0200 Subject: [PATCH] web page tweaks --- .../asdf00/visionfive/hc/GlobalDataStore.kt | 3 +- .../dev/asdf00/visionfive/hc/server/Main.kt | 57 +++++++++++-------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/main/kotlin/dev/asdf00/visionfive/hc/GlobalDataStore.kt b/src/main/kotlin/dev/asdf00/visionfive/hc/GlobalDataStore.kt index 72cbb6b..2e25926 100644 --- a/src/main/kotlin/dev/asdf00/visionfive/hc/GlobalDataStore.kt +++ b/src/main/kotlin/dev/asdf00/visionfive/hc/GlobalDataStore.kt @@ -1,14 +1,13 @@ package dev.asdf00.visionfive.hc import java.util.* -import java.util.concurrent.CopyOnWriteArraySet object GlobalDataStore { @Volatile var temperature = 0.0 @Volatile var tempUpdated = Date() @Volatile var isSunny = true - val allowedTempUpdates = CopyOnWriteArraySet() + @Volatile var targetTemp = 22.5 @Volatile var pval = 0.0 @Volatile var ival = 1.0 @Volatile var dval = 2.0 diff --git a/src/main/kotlin/dev/asdf00/visionfive/hc/server/Main.kt b/src/main/kotlin/dev/asdf00/visionfive/hc/server/Main.kt index f545a33..ecea7c3 100644 --- a/src/main/kotlin/dev/asdf00/visionfive/hc/server/Main.kt +++ b/src/main/kotlin/dev/asdf00/visionfive/hc/server/Main.kt @@ -8,27 +8,8 @@ import java.util.* import org.json.JSONObject fun main() { + // out-facing web page val server = buildWebServer(8030) { - // data collection - endpoint("temp") handler@{ exchange -> - if (exchange.remoteAddress.address.toString() !in GlobalDataStore.allowedTempUpdates) { - exchange.replyCat(403) - } - exchange.requestURI.query.split("&").forEach { - if (it.startsWith("t=")) { - it.substring(2).toDoubleOrNull()?.let { - GlobalDataStore.temperature = it - GlobalDataStore.tempUpdated = Date() - exchange.replyCat(200) - } ?: run { - exchange.replyCat(400) - } - return@handler - } - } - exchange.replyCat(400) - } - // main landing page endpoint("") { exchange -> exchange.responseHeaders.add("Cache-Control", "no-store") @@ -53,6 +34,7 @@ fun main() {

PID values

+ @@ -62,6 +44,7 @@ fun main() {
Temp:
P:
I:
D: