Skip to content

Commit

Permalink
Allow to set a custom timezoned server
Browse files Browse the repository at this point in the history
  • Loading branch information
dos1 committed Sep 17, 2021
1 parent 7b3c8aa commit 054bcbe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();`
Expand Down Expand Up @@ -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_SERVER`, `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
Expand Down
9 changes: 8 additions & 1 deletion src/ezTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions src/ezTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 054bcbe

Please sign in to comment.