Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manual Posix timezone string support to allow offline Clockwise clock #42

Merged
merged 6 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions firmware/lib/cw-commons/CWDateTime.cpp
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
2 changes: 1 addition & 1 deletion firmware/lib/cw-commons/CWDateTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions firmware/lib/cw-commons/CWPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,6 +39,7 @@ struct ClockwiseParams
String ntpServer;
String canvasFile;
String canvasServer;
String manualPosix;


ClockwiseParams() {
Expand Down Expand Up @@ -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()
Expand All @@ -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, "");
}

};
3 changes: 3 additions & 0 deletions firmware/lib/cw-commons/CWWebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions firmware/lib/cw-commons/SettingsWebPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. <a href=\"https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv\">Click here for a list.</a>",
formInput: "<input id='posixString' class='w3-input w3-light-grey' name='posixString' type='text' placeholder='Manual Posix String' value='" + settings.manualposix + "'>",
icon: "fa-globe",
save: "updatePreference('manualPosix', posixString.value)",
property: "manualPosix"
}
];

Expand Down
5 changes: 4 additions & 1 deletion firmware/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down