Add error recovery when UDP transfer fails

This commit does not affect normal case. Even if UDP transfer fails for
any reasons in sendNTPPacket, it can be recovered by re-initialization.
This commit is contained in:
kzhioki 2019-12-12 09:50:33 +09:00
parent 6645bf44e8
commit 079cdafe0f

View File

@ -201,7 +201,11 @@ void NTPClient::sendNTPPacket() {
this->_udp->beginPacket(this->_poolServerIP, 123);
}
this->_udp->write(this->_packetBuffer, NTP_PACKET_SIZE);
this->_udp->endPacket();
if (this->_udp->endPacket() == 0) {
// recovery if UDP client encounters any errors
this->end();
this->begin(this->_port);
}
}
void NTPClient::setRandomPort(unsigned int minValue, unsigned int maxValue) {