From 2cdabd5cd89f124b116595bbc68d405cee1a59bd Mon Sep 17 00:00:00 2001 From: rackrick <45207681+rackrick@users.noreply.github.com> Date: Sun, 28 Mar 2021 16:45:44 +0200 Subject: [PATCH] moved utcoffset to config --- firmware/data/include/moonwatch.js | 2 ++ firmware/data/index.html | 8 ++++++++ firmware/data/moonwatch.json | 3 ++- firmware/src/MoonWatch.cpp | 9 +++++++++ firmware/src/Webserver/WebServer.cpp | 2 ++ firmware/src/tools/ConfigStore.cpp | 6 +++--- firmware/src/tools/GeneralConfig.h | 1 + firmware/src/tools/NtpClock.cpp | 7 +++---- firmware/src/tools/NtpClock.h | 5 +++++ 9 files changed, 35 insertions(+), 8 deletions(-) diff --git a/firmware/data/include/moonwatch.js b/firmware/data/include/moonwatch.js index 335858e..b9252c1 100644 --- a/firmware/data/include/moonwatch.js +++ b/firmware/data/include/moonwatch.js @@ -12,6 +12,7 @@ function updateConfig(data) { // general settings document.getElementById("wifi").value = data.general.wifi; document.getElementById("display").value = data.general.display; + document.getElementById("utcOffset").value = data.general.utcOffset; // printers for (let i = 0; i < data.printers.length; i++) { @@ -36,6 +37,7 @@ function save() { wifi: document.getElementById("wifi").value, password: document.getElementById("password").value, display: document.getElementById("display").value, + utcOffset: document.getElementById("utcOffset").value, }, printers: [], led: { diff --git a/firmware/data/index.html b/firmware/data/index.html index 70d3cc9..e0d1463 100644 --- a/firmware/data/index.html +++ b/firmware/data/index.html @@ -42,6 +42,14 @@

Welcome to MoonWatch

(currently only ST7735 Displays are supported) + + + utc Offset (Timezone): + + + + + Printers diff --git a/firmware/data/moonwatch.json b/firmware/data/moonwatch.json index ad4bfdc..2490921 100644 --- a/firmware/data/moonwatch.json +++ b/firmware/data/moonwatch.json @@ -2,7 +2,8 @@ "general": { "wifi": "", "password": "", - "display": 0 + "display": 0, + "utcOffset": 2 }, "printers": [ { diff --git a/firmware/src/MoonWatch.cpp b/firmware/src/MoonWatch.cpp index 5033101..f6f2635 100644 --- a/firmware/src/MoonWatch.cpp +++ b/firmware/src/MoonWatch.cpp @@ -230,6 +230,9 @@ void MoonWatch::startMonitor() { lcd->showPrinterScreen(printerName, printer); } } else { + Serial.println("idle screen: " + config.printers[activePrinter].Name); + Serial.println(printer.connectionState); + lcd->showIdleScreen(); leds[printerLed] = CRGB::Black; } @@ -265,6 +268,8 @@ void MoonWatch::startMonitor() { bool MoonWatch::switchPrinter(std::vector printers) { + Serial.println(F("Try to switch")); + uint nextPrinter = activePrinter; // with one printer we can't switch @@ -278,13 +283,17 @@ bool MoonWatch::switchPrinter(std::vector printers) { nextPrinter = 0; } + Serial.println("try next printer " + printers[nextPrinter].Name + "(" + nextPrinter + ")"); + MoonrakerClient mrClient; printer = mrClient.getData(printers[nextPrinter].Host); if (printer.connectionState == "success") { + Serial.println(F("success, switch printer")); activePrinter = nextPrinter; return true; } else { + Serial.println(F("error, printer not reachable. skip.")); leds[printers[nextPrinter].Led] = CRGB::Black; return false; diff --git a/firmware/src/Webserver/WebServer.cpp b/firmware/src/Webserver/WebServer.cpp index 3ed94f0..a824bb0 100644 --- a/firmware/src/Webserver/WebServer.cpp +++ b/firmware/src/Webserver/WebServer.cpp @@ -81,6 +81,7 @@ namespace RP { config.display = jsonObj["general"]["display"].as(); } else { config.display = jsonObj["general"]["display"].as(); + config.utcOffset = jsonObj["general"]["utcOffset"].as(); } bool updateGeneral = configStore.updateGeneral(config); @@ -125,6 +126,7 @@ namespace RP { // reset esp server.on("/reset", HTTP_GET, [](AsyncWebServerRequest *request){ Serial.println(F("reset called")); + request->send(200, "application/json", "{ \"status\": \"ok\" }"); ESP.reset(); }); diff --git a/firmware/src/tools/ConfigStore.cpp b/firmware/src/tools/ConfigStore.cpp index df7ea63..fa473f7 100644 --- a/firmware/src/tools/ConfigStore.cpp +++ b/firmware/src/tools/ConfigStore.cpp @@ -33,13 +33,11 @@ namespace RP { return false; } - Serial.println("Json:"); - Serial.println(doc.as()); - // general config general.wifi = doc["general"]["wifi"].as(); general.password = doc["general"]["password"].as(); general.display = doc["general"]["display"].as(); + general.utcOffset = doc["general"]["utcoffset"].as(); // printers array JsonArray arrPrinters = doc["printers"].as(); @@ -69,6 +67,7 @@ namespace RP { json["general"]["wifi"] = general.wifi; json["general"]["password"] = general.password; json["general"]["display"] = general.display; + json["general"]["utcoffset"] = general.utcOffset; JsonArray arrPrinters = json["printers"].as(); @@ -113,6 +112,7 @@ namespace RP { } general.display = newConfig.display; + general.utcOffset = newConfig.utcOffset; return true; } diff --git a/firmware/src/tools/GeneralConfig.h b/firmware/src/tools/GeneralConfig.h index 85a0f3f..7487554 100644 --- a/firmware/src/tools/GeneralConfig.h +++ b/firmware/src/tools/GeneralConfig.h @@ -7,5 +7,6 @@ namespace RP { String wifi; String password; int display; + int utcOffset; }; } \ No newline at end of file diff --git a/firmware/src/tools/NtpClock.cpp b/firmware/src/tools/NtpClock.cpp index 06b048d..61f242f 100644 --- a/firmware/src/tools/NtpClock.cpp +++ b/firmware/src/tools/NtpClock.cpp @@ -12,8 +12,6 @@ namespace RP { return instance; } - //1613519630 - String NtpClock::getDateTimeString() { // tick tack clock tickTime(); @@ -67,8 +65,9 @@ namespace RP { if (!ntpSuccess) { delay(1000); } - - long utcOffset = 1 * 60 * 60; //TODO: Get from config + + ConfigStore& config = ConfigStore::getInstance(); + long utcOffset = config.general.utcOffset; WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffset); timeClient.begin(); diff --git a/firmware/src/tools/NtpClock.h b/firmware/src/tools/NtpClock.h index fee312b..d04ccb9 100644 --- a/firmware/src/tools/NtpClock.h +++ b/firmware/src/tools/NtpClock.h @@ -2,6 +2,11 @@ #include #include +#ifndef ConfigStoreH + #define ConfigStoreH + #include "ConfigStore.h" +#endif + namespace RP { namespace Tools