Merge pull request #17 from SirUli/master

Added functions for changing the timeOffset and updateInterval later
This commit is contained in:
FWeinb 2016-05-25 21:30:40 +02:00
commit 7433f7da88
4 changed files with 27 additions and 7 deletions

View File

@ -140,6 +140,14 @@ void NTPClient::end() {
this->_udpSetup = false;
}
void NTPClient::setTimeOffset(int timeOffset) {
this->_timeOffset = timeOffset;
}
void NTPClient::setUpdateInterval(int updateInterval) {
this->_updateInterval = updateInterval;
}
void NTPClient::sendNTPPacket() {
// set all bytes in the buffer to 0
memset(this->_packetBuffer, 0, NTP_PACKET_SIZE);
@ -161,4 +169,3 @@ void NTPClient::sendNTPPacket() {
this->_udp->write(this->_packetBuffer, NTP_PACKET_SIZE);
this->_udp->endPacket();
}

View File

@ -63,6 +63,17 @@ class NTPClient {
int getMinutes();
int getSeconds();
/**
* Changes the time offset. Useful for changing timezones dynamically
*/
void setTimeOffset(int timeOffset);
/**
* Set the update interval to another frequency. E.g. useful when the
* timeOffset should not be set in the constructor
*/
void setUpdateInterval(int updateInterval);
/**
* @return time formatted like `hh:mm:ss`
*/

View File

@ -1,4 +1,4 @@
# NTPClient
# NTPClient
[![Build Status](https://travis-ci.org/arduino-libraries/NTPClient.svg?branch=master)](https://travis-ci.org/arduino-libraries/NTPClient)
@ -17,7 +17,8 @@ const char *password = "<PASSWORD>";
WiFiUDP ntpUDP;
// By default 'time.nist.gov' is used.
// By default 'time.nist.gov' is used with 60 seconds update interval and
// no offset
NTPClient timeClient(ntpUDP);
// You can specify the time server pool and the offset, (in seconds)
@ -38,9 +39,9 @@ void setup(){
void loop() {
timeClient.update();
Serial.println(timeClient.getFormattedTime());
delay(1000);
}
```

View File

@ -10,8 +10,9 @@ const char *password = "<PASSWORD>";
WiFiUDP ntpUDP;
// You can specify the time server pool and the offset, (in seconds)
// additionaly you can specify the update interval (in milliseconds).
// You can specify the time server pool and the offset (in seconds, can be
// changed later with setTimeOffset() ). Additionaly you can specify the
// update interval (in milliseconds, can be changed using setUpdateInterval() ).
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);
void setup(){