The flush at the start of ntpUpdate() is mandatory to keep the NTP server in sync after an UDP timeout.
If you leave out the flush sometimes suddenly an exact NTP::updateInterval timeshift will happen.
The code I use to fix this was:
bool NTP::ntpUpdate() {
// flush any existing pending input packets
while(udp->parsePacket() != 0) udp->flush();
if (server == nullptr) udp->beginPacket(serverIP, NTP_PORT);
else udp->beginPacket(server, NTP_PORT);
The flush at the start of ntpUpdate() is mandatory to keep the NTP server in sync after an UDP timeout.
If you leave out the flush sometimes suddenly an exact NTP::updateInterval timeshift will happen.
The code I use to fix this was:
bool NTP::ntpUpdate() {
// flush any existing pending input packets
while(udp->parsePacket() != 0) udp->flush();
if (server == nullptr) udp->beginPacket(serverIP, NTP_PORT);
else udp->beginPacket(server, NTP_PORT);