Skip to content

Added setPoolServerIP #125

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 12 additions & 3 deletions NTPClient.cpp
Original file line number Diff line number Diff line change
@@ -98,11 +98,15 @@ bool NTPClient::forceUpdate() {
do {
delay ( 10 );
cb = this->_udp->parsePacket();
if (timeout > 100) return false; // timeout after 1000 ms
if (timeout > 100) {
this->_lastUpdateOk = false;
return false; // timeout after 1000 ms
}
timeout++;
} while (cb == 0);

this->_lastUpdate = millis() - (10 * (timeout + 1)); // Account for delay in reading the time
this->_lastUpdateOk = true;

this->_udp->read(this->_packetBuffer, NTP_PACKET_SIZE);

@@ -123,7 +127,7 @@ bool NTPClient::update() {
if (!this->_udpSetup || this->_port != NTP_DEFAULT_LOCAL_PORT) this->begin(this->_port); // setup the UDP client if needed
return this->forceUpdate();
}
return false; // return false if update does not occur
return this->_lastUpdateOk; // return last sync state
}

unsigned long NTPClient::getEpochTime() const {
@@ -174,7 +178,12 @@ void NTPClient::setUpdateInterval(unsigned long updateInterval) {
}

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

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

void NTPClient::sendNTPPacket() {
8 changes: 8 additions & 0 deletions NTPClient.h
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ class NTPClient {

unsigned long _currentEpoc = 0; // In s
unsigned long _lastUpdate = 0; // In ms
bool _lastUpdateOk = false; //

byte _packetBuffer[NTP_PACKET_SIZE];

@@ -44,6 +45,13 @@ class NTPClient {
*/
void setPoolServerName(const char* poolServerName);

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

/**
* Set random local port
*/