From 4a08b189d55982ded7ff0f68880b812784de9d10 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Fri, 17 Sep 2021 05:58:42 +0200 Subject: [PATCH] Allow to set a custom timezoned server --- README.md | 9 +++++++++ src/ezTime.cpp | 9 ++++++++- src/ezTime.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9fd1c0a..3ee9c69 100644 --- a/README.md +++ b/README.md @@ -264,6 +264,14 @@ By default, ezTime is set to poll `pool.ntp.org` about every 30 minutes. These d   +#### *setTimezoneServer* + +`void setTimezoneServer(String timezone_server = TIMEZONED_REMOTE_HOST, uint16_t timezone_port = TIMEZONED_REMOTE_PORT);` + +By default, ezTime uses [`timezoned.rop.nl`](#timezonedropnl) service to resolve timezone data when using [`setLocation`](#setlocation). You can switch to another server with `setTimezoneServer`. + +  + ### *updateNTP* `void updateNTP();` @@ -1083,6 +1091,7 @@ ezTime 0.7.2 runs fine (No networking on board, so tested with NoNetwork example | [**`setLocation`**](#setlocation) | `bool` | `String location = ""` | yes | yes | no | [**`setPosix`**](#setposix) | `bool` | `String posix` | yes | yes | no | [**`setServer`**](#setserver-and-setinterval) | `void` | `String ntp_server = NTP_SERVER` | no | yes | no +| [**`setTimezoneServer`**](#settimezoneserver) | `void` | `String timezone_server = TIMEZONED_REMOTE_HOST`, `uint16_t timezone_port = TIMEZONED_REMOTE_PORT` | no | yes | no | [**`setTime`**](#settime) | `void` | `time_t t`, `uint16_t ms = 0` | optional | no | no | [**`setTime`**](#settime) | `void` | `uint8_t hr`, `uint8_t min`, `uint8_t sec`, `uint8_t day`, `uint8_t mnth`, `uint16_t yr` | optional | no | no | [**`timeStatus`**](#timestatus) | `timeStatus_t` | | no | no | no diff --git a/src/ezTime.cpp b/src/ezTime.cpp index 78d4399..0cef926 100644 --- a/src/ezTime.cpp +++ b/src/ezTime.cpp @@ -79,6 +79,8 @@ namespace { #ifdef EZTIME_NETWORK_ENABLE uint16_t _ntp_interval = NTP_INTERVAL; String _ntp_server = NTP_SERVER; + String _timezone_server = TIMEZONED_REMOTE_HOST; + uint16_t _timezone_port = TIMEZONED_REMOTE_PORT; #endif void triggerError(const ezError_t err) { @@ -518,6 +520,11 @@ namespace ezt { void setServer(const String ntp_server /* = NTP_SERVER */) { _ntp_server = ntp_server; } + void setTimezoneServer(const String timezone_server /* = TIMEZONED_REMOTE_HOST */, const uint16_t timezone_port /* = TIMEZONED_REMOTE_PORT */) { + _timezone_server = timezone_server; + _timezone_port = timezone_port; + } + bool waitForSync(const uint16_t timeout /* = 0 */) { unsigned long start = millis(); @@ -818,7 +825,7 @@ String Timezone::getPosix() { return _posix; } udp.flush(); udp.begin(TIMEZONED_LOCAL_PORT); unsigned long started = millis(); - udp.beginPacket(TIMEZONED_REMOTE_HOST, TIMEZONED_REMOTE_PORT); + udp.beginPacket(_timezone_server.c_str(), _timezone_port); udp.write((const uint8_t*)location.c_str(), location.length()); udp.endPacket(); diff --git a/src/ezTime.h b/src/ezTime.h index d849847..759f6bc 100644 --- a/src/ezTime.h +++ b/src/ezTime.h @@ -202,6 +202,7 @@ namespace ezt { bool queryNTP(const String server, time_t &t, unsigned long &measured_at); void setInterval(const uint16_t seconds = 0); void setServer(const String ntp_server = NTP_SERVER); + void setTimezoneServer(const String timezone_server = TIMEZONED_REMOTE_HOST, const uint16_t timezone_port = TIMEZONED_REMOTE_PORT); void updateNTP(); bool waitForSync(const uint16_t timeout = 0); time_t lastNtpUpdateTime();