Skip to content

Commit 7433f7d

Browse files
committed
Merge pull request #17 from SirUli/master
Added functions for changing the timeOffset and updateInterval later
2 parents d9264aa + 85c4cac commit 7433f7d

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

NTPClient.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ void NTPClient::end() {
140140
this->_udpSetup = false;
141141
}
142142

143+
void NTPClient::setTimeOffset(int timeOffset) {
144+
this->_timeOffset = timeOffset;
145+
}
146+
147+
void NTPClient::setUpdateInterval(int updateInterval) {
148+
this->_updateInterval = updateInterval;
149+
}
150+
143151
void NTPClient::sendNTPPacket() {
144152
// set all bytes in the buffer to 0
145153
memset(this->_packetBuffer, 0, NTP_PACKET_SIZE);
@@ -161,4 +169,3 @@ void NTPClient::sendNTPPacket() {
161169
this->_udp->write(this->_packetBuffer, NTP_PACKET_SIZE);
162170
this->_udp->endPacket();
163171
}
164-

NTPClient.h

+11
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ class NTPClient {
6363
int getMinutes();
6464
int getSeconds();
6565

66+
/**
67+
* Changes the time offset. Useful for changing timezones dynamically
68+
*/
69+
void setTimeOffset(int timeOffset);
70+
71+
/**
72+
* Set the update interval to another frequency. E.g. useful when the
73+
* timeOffset should not be set in the constructor
74+
*/
75+
void setUpdateInterval(int updateInterval);
76+
6677
/**
6778
* @return time formatted like `hh:mm:ss`
6879
*/

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# NTPClient
1+
# NTPClient
22

33
[![Build Status](https://travis-ci.org/arduino-libraries/NTPClient.svg?branch=master)](https://travis-ci.org/arduino-libraries/NTPClient)
44

@@ -17,7 +17,8 @@ const char *password = "<PASSWORD>";
1717

1818
WiFiUDP ntpUDP;
1919

20-
// By default 'time.nist.gov' is used.
20+
// By default 'time.nist.gov' is used with 60 seconds update interval and
21+
// no offset
2122
NTPClient timeClient(ntpUDP);
2223

2324
// You can specify the time server pool and the offset, (in seconds)
@@ -38,9 +39,9 @@ void setup(){
3839

3940
void loop() {
4041
timeClient.update();
41-
42+
4243
Serial.println(timeClient.getFormattedTime());
43-
44+
4445
delay(1000);
4546
}
4647
```

examples/Advanced/Advanced.ino

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ const char *password = "<PASSWORD>";
1010

1111
WiFiUDP ntpUDP;
1212

13-
// You can specify the time server pool and the offset, (in seconds)
14-
// additionaly you can specify the update interval (in milliseconds).
13+
// You can specify the time server pool and the offset (in seconds, can be
14+
// changed later with setTimeOffset() ). Additionaly you can specify the
15+
// update interval (in milliseconds, can be changed using setUpdateInterval() ).
1516
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);
1617

1718
void setup(){

0 commit comments

Comments
 (0)