diff --git a/firmware/lib/cw-commons/CWDateTime.cpp b/firmware/lib/cw-commons/CWDateTime.cpp index 5645eef..e0aa9f2 100644 --- a/firmware/lib/cw-commons/CWDateTime.cpp +++ b/firmware/lib/cw-commons/CWDateTime.cpp @@ -1,11 +1,19 @@ #include "CWDateTime.h" -void CWDateTime::begin(const char *timeZone, bool use24format, const char *ntpServer = NTP_SERVER) +void CWDateTime::begin(const char *timeZone, bool use24format, const char *ntpServer = NTP_SERVER, const char *posixTZ = "") { Serial.printf("[Time] NTP Server: %s, Timezone: %s\n", ntpServer, timeZone); - ezt::setServer(String(ntpServer)); - myTZ.setLocation(timeZone); + + if (strlen(posixTZ) > 1) { + // An empty value still contains a null character so not empty is a value greater than 1. + // Set to defined Posix TZ + myTZ.setPosix(posixTZ); + } else { + // Use automatic eztime remote lookup + myTZ.setLocation(timeZone); + } + this->use24hFormat = use24format; ezt::updateNTP(); waitForSync(); diff --git a/firmware/lib/cw-commons/CWDateTime.h b/firmware/lib/cw-commons/CWDateTime.h index d3eb583..6add607 100644 --- a/firmware/lib/cw-commons/CWDateTime.h +++ b/firmware/lib/cw-commons/CWDateTime.h @@ -11,7 +11,7 @@ class CWDateTime bool use24hFormat = true; public: - void begin(const char *timeZone, bool use24format, const char *ntpServer); + void begin(const char *timeZone, bool use24format, const char *ntpServer, const char *posixTZ); String getFormattedTime(); String getFormattedTime(const char* format); diff --git a/firmware/lib/cw-commons/CWPreferences.h b/firmware/lib/cw-commons/CWPreferences.h index d1d7a67..1fbd61b 100644 --- a/firmware/lib/cw-commons/CWPreferences.h +++ b/firmware/lib/cw-commons/CWPreferences.h @@ -24,6 +24,7 @@ struct ClockwiseParams const char* const PREF_NTP_SERVER = "ntpServer"; const char* const PREF_CANVAS_FILE = "canvasFile"; const char* const PREF_CANVAS_SERVER = "canvasServer"; + const char* const PREF_MANUAL_POSIX = "manualPosix"; bool swapBlueGreen; @@ -38,6 +39,7 @@ struct ClockwiseParams String ntpServer; String canvasFile; String canvasServer; + String manualPosix; ClockwiseParams() { @@ -65,6 +67,7 @@ struct ClockwiseParams preferences.putString(PREF_NTP_SERVER, ntpServer); preferences.putString(PREF_CANVAS_FILE, canvasFile); preferences.putString(PREF_CANVAS_SERVER, canvasServer); + preferences.putString(PREF_MANUAL_POSIX, manualPosix); } void load() @@ -81,6 +84,7 @@ struct ClockwiseParams ntpServer = preferences.getString(PREF_NTP_SERVER, NTP_SERVER); canvasFile = preferences.getString(PREF_CANVAS_FILE, ""); canvasServer = preferences.getString(PREF_CANVAS_SERVER, "raw.githubusercontent.com"); + manualPosix = preferences.getString(PREF_MANUAL_POSIX, ""); } }; diff --git a/firmware/lib/cw-commons/CWWebServer.h b/firmware/lib/cw-commons/CWWebServer.h index c5f95f3..12590c6 100644 --- a/firmware/lib/cw-commons/CWWebServer.h +++ b/firmware/lib/cw-commons/CWWebServer.h @@ -123,6 +123,8 @@ struct ClockwiseWebServer ClockwiseParams::getInstance()->canvasFile = value; } else if (key == ClockwiseParams::getInstance()->PREF_CANVAS_SERVER) { ClockwiseParams::getInstance()->canvasServer = value; + } else if (key == ClockwiseParams::getInstance()->PREF_MANUAL_POSIX) { + ClockwiseParams::getInstance()->manualPosix = value; } ClockwiseParams::getInstance()->save(); client.println("HTTP/1.0 204 No Content"); @@ -157,6 +159,7 @@ struct ClockwiseWebServer client.printf(HEADER_TEMPLATE_S, ClockwiseParams::getInstance()->PREF_NTP_SERVER, ClockwiseParams::getInstance()->ntpServer.c_str()); client.printf(HEADER_TEMPLATE_S, ClockwiseParams::getInstance()->PREF_CANVAS_FILE, ClockwiseParams::getInstance()->canvasFile.c_str()); client.printf(HEADER_TEMPLATE_S, ClockwiseParams::getInstance()->PREF_CANVAS_SERVER, ClockwiseParams::getInstance()->canvasServer.c_str()); + client.printf(HEADER_TEMPLATE_S, ClockwiseParams::getInstance()->PREF_MANUAL_POSIX, ClockwiseParams::getInstance()->manualPosix.c_str()); client.printf(HEADER_TEMPLATE_S, "CW_FW_VERSION", CW_FW_VERSION); client.printf(HEADER_TEMPLATE_S, "CW_FW_NAME", CW_FW_NAME); diff --git a/firmware/lib/cw-commons/SettingsWebPage.h b/firmware/lib/cw-commons/SettingsWebPage.h index 5798be4..7bd6272 100644 --- a/firmware/lib/cw-commons/SettingsWebPage.h +++ b/firmware/lib/cw-commons/SettingsWebPage.h @@ -127,6 +127,14 @@ const char SETTINGS_PAGE[] PROGMEM = R""""( save: "updatePreference('canvasServer', serverAddress.value)", property: "canvasServer", exclusive: "cw-cf-0x07" + }, + { + title: "Posix Timezone String", + description: "To avoid remote lookups, provide a Posix string that corresponds to your timezone. Leave empty to obtain this automatically from the server. Click here for a list.", + formInput: "", + icon: "fa-globe", + save: "updatePreference('manualPosix', posixString.value)", + property: "manualPosix" } ]; diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index e148067..a5b4f74 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -96,7 +96,10 @@ void setup() if (wifi.begin()) { StatusController::getInstance()->ntpConnecting(); - cwDateTime.begin(ClockwiseParams::getInstance()->timeZone.c_str(), ClockwiseParams::getInstance()->use24hFormat, ClockwiseParams::getInstance()->ntpServer.c_str()); + cwDateTime.begin(ClockwiseParams::getInstance()->timeZone.c_str(), + ClockwiseParams::getInstance()->use24hFormat, + ClockwiseParams::getInstance()->ntpServer.c_str(), + ClockwiseParams::getInstance()->manualPosix.c_str()); clockface->setup(&cwDateTime); } }