Skip to content

Commit

Permalink
moved utcoffset to config
Browse files Browse the repository at this point in the history
  • Loading branch information
rackrick committed Mar 28, 2021
1 parent 8f63c2a commit 2cdabd5
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 8 deletions.
2 changes: 2 additions & 0 deletions firmware/data/include/moonwatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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: {
Expand Down
8 changes: 8 additions & 0 deletions firmware/data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ <h2>Welcome to MoonWatch</h2>
(currently only ST7735 Displays are supported)
</td>
</tr>
<tr>
<td class="label">
utc Offset (Timezone):
</td>
<td class="utcOffset">
<input type="number" id="utcOffset">
</td>
</tr>
<!-- PRINTER SETTINGS -->
<tr>
<td colspan="2" class="headline">Printers</td>
Expand Down
3 changes: 2 additions & 1 deletion firmware/data/moonwatch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"general": {
"wifi": "",
"password": "",
"display": 0
"display": 0,
"utcOffset": 2
},
"printers": [
{
Expand Down
9 changes: 9 additions & 0 deletions firmware/src/MoonWatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -265,6 +268,8 @@ void MoonWatch::startMonitor() {

bool MoonWatch::switchPrinter(std::vector<PrinterConfig> printers) {

Serial.println(F("Try to switch"));

uint nextPrinter = activePrinter;

// with one printer we can't switch
Expand All @@ -278,13 +283,17 @@ bool MoonWatch::switchPrinter(std::vector<PrinterConfig> 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;
Expand Down
2 changes: 2 additions & 0 deletions firmware/src/Webserver/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ namespace RP {
config.display = jsonObj["general"]["display"].as<int>();
} else {
config.display = jsonObj["general"]["display"].as<int>();
config.utcOffset = jsonObj["general"]["utcOffset"].as<int>();
}

bool updateGeneral = configStore.updateGeneral(config);
Expand Down Expand Up @@ -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();
});

Expand Down
6 changes: 3 additions & 3 deletions firmware/src/tools/ConfigStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ namespace RP {
return false;
}

Serial.println("Json:");
Serial.println(doc.as<String>());

// general config
general.wifi = doc["general"]["wifi"].as<String>();
general.password = doc["general"]["password"].as<String>();
general.display = doc["general"]["display"].as<int>();
general.utcOffset = doc["general"]["utcoffset"].as<int>();

// printers array
JsonArray arrPrinters = doc["printers"].as<JsonArray>();
Expand Down Expand Up @@ -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<JsonArray>();

Expand Down Expand Up @@ -113,6 +112,7 @@ namespace RP {
}

general.display = newConfig.display;
general.utcOffset = newConfig.utcOffset;

return true;
}
Expand Down
1 change: 1 addition & 0 deletions firmware/src/tools/GeneralConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ namespace RP {
String wifi;
String password;
int display;
int utcOffset;
};
}
7 changes: 3 additions & 4 deletions firmware/src/tools/NtpClock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ namespace RP {
return instance;
}

//1613519630

String NtpClock::getDateTimeString() {
// tick tack clock
tickTime();
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions firmware/src/tools/NtpClock.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

#ifndef ConfigStoreH
#define ConfigStoreH
#include "ConfigStore.h"
#endif

namespace RP
{
namespace Tools
Expand Down

0 comments on commit 2cdabd5

Please sign in to comment.