Closed
Description
I've modified NTPClient() to accept an IP address as an alternative to the usual server name. This often speeds up an NTP fetch by avoiding the DNS lookup step.
NTPClient.h:
const char* _poolServerName = "time.nist.gov"; // Default time server
IPAddress _poolServerIP;
NTPClient(UDP& udp, int timeOffset);
NTPClient(UDP& udp, IPAddress poolServerIP);
NTPClient(UDP& udp, const char* poolServerName);
NTPClient.cpp:
NTPClient::NTPClient(UDP& udp, IPAddress poolServerIP) {
this->_udp = &udp;
this->_poolServerIP = poolServerIP;
this->_poolServerName = NULL;
}
// you can send a packet requesting a timestamp:
if (this->_poolServerName) this->_udp->beginPacket(this->_poolServerName, 123); // NTP requests are to port 123
else this->_udp->beginPacket(this->_poolServerIP, 123);
this->_udp->write(this->_packetBuffer, NTP_PACKET_SIZE);
Metadata
Metadata
Assignees
Labels
No labels