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

Some useful methods to change NTP server dynamically. #220

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions NTPClient.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,35 @@ void NTPClient::setTimeOffset(int timeOffset) {
this->_timeOffset = timeOffset;
}

long NTPClient::getTimeOffset() {
return this->_timeOffset;
}

void NTPClient::setUpdateInterval(unsigned long updateInterval) {
this->_updateInterval = updateInterval;
}

unsigned long NTPClient::getUpdateInterval() {
return this->_updateInterval;
}

void NTPClient::setPoolServerName(const char* poolServerName) {
this->_poolServerName = poolServerName;
}

const char *NTPClient::getPoolServerName() {
return this->_poolServerName;
}

void NTPClient::setPoolServerIP(IPAddress poolServerIP) {
this->_poolServerIP = poolServerIP;
this->_poolServerName = NULL;
}

IPAddress NTPClient::getPoolServerIP() {
return this->_poolServerIP;
}

void NTPClient::sendNTPPacket() {
// set all bytes in the buffer to 0
memset(this->_packetBuffer, 0, NTP_PACKET_SIZE);
Expand Down Expand Up @@ -210,3 +231,7 @@ void NTPClient::setRandomPort(unsigned int minValue, unsigned int maxValue) {
randomSeed(analogRead(0));
this->_port = random(minValue, maxValue);
}

void NTPClient::setLastUpdate(unsigned long sec) {
this->_lastUpdate = sec;
}
32 changes: 32 additions & 0 deletions NTPClient.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ class NTPClient {
*/
void setPoolServerName(const char* poolServerName);

/**
* Get time server name
*/
const char *getPoolServerName();

/**
* Set time server IP
*
* @param poolServerIP
*/
void setPoolServerIP(IPAddress poolServerIP);

/*
* Get time server IP
*/
IPAddress getPoolServerIP();

/**
* Set random local port
*/
Expand Down Expand Up @@ -91,12 +108,22 @@ class NTPClient {
*/
void setTimeOffset(int timeOffset);

/**
* Get the time offset
*/
long getTimeOffset();

/**
* Set the update interval to another frequency. E.g. useful when the
* timeOffset should not be set in the constructor
*/
void setUpdateInterval(unsigned long updateInterval);

/**
* Get the update interval
*/
unsigned long getUpdateInterval();

/**
* @return time formatted like `hh:mm:ss`
*/
Expand All @@ -111,4 +138,9 @@ class NTPClient {
* Stops the underlying UDP client
*/
void end();

/**
* Set the last update time
*/
void setLastUpdate(unsigned long sec);
};
Loading