From 5a93a546515b7582711caa17742b998dc56abbda Mon Sep 17 00:00:00 2001 From: MHotchin Date: Fri, 30 Sep 2022 23:12:35 -0700 Subject: [PATCH 1/2] Add more error checking. --- NTPClient.cpp | 23 ++++++++++++++++------- NTPClient.h | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/NTPClient.cpp b/NTPClient.cpp index b435855..7bb9ad7 100755 --- a/NTPClient.cpp +++ b/NTPClient.cpp @@ -90,7 +90,8 @@ bool NTPClient::forceUpdate() { while(this->_udp->parsePacket() != 0) this->_udp->flush(); - this->sendNTPPacket(); + if (!this->sendNTPPacket()) + return false; // Wait till data is there or timeout... byte timeout = 0; @@ -104,7 +105,8 @@ bool NTPClient::forceUpdate() { this->_lastUpdate = millis() - (10 * (timeout + 1)); // Account for delay in reading the time - this->_udp->read(this->_packetBuffer, NTP_PACKET_SIZE); + if (this->_udp->read(this->_packetBuffer, NTP_PACKET_SIZE) != NTP_PACKET_SIZE) + return false; unsigned long highWord = word(this->_packetBuffer[40], this->_packetBuffer[41]); unsigned long lowWord = word(this->_packetBuffer[42], this->_packetBuffer[43]); @@ -181,7 +183,7 @@ void NTPClient::setPoolServerName(const char* poolServerName) { this->_poolServerName = poolServerName; } -void NTPClient::sendNTPPacket() { +bool NTPClient::sendNTPPacket() { // set all bytes in the buffer to 0 memset(this->_packetBuffer, 0, NTP_PACKET_SIZE); // Initialize values needed to form NTP request @@ -197,13 +199,20 @@ void NTPClient::sendNTPPacket() { // all NTP fields have been given values, now // you can send a packet requesting a timestamp: + + bool success = false; if (this->_poolServerName) { - this->_udp->beginPacket(this->_poolServerName, 123); + success = this->_udp->beginPacket(this->_poolServerName, 123); } else { - this->_udp->beginPacket(this->_poolServerIP, 123); + success = this->_udp->beginPacket(this->_poolServerIP, 123); } - this->_udp->write(this->_packetBuffer, NTP_PACKET_SIZE); - this->_udp->endPacket(); + + if (success) + if (this->_udp->write(this->_packetBuffer, NTP_PACKET_SIZE) == NTP_PACKET_SIZE) + if (this->_udp->endPacket()) + return true; + + return false; } void NTPClient::setRandomPort(unsigned int minValue, unsigned int maxValue) { diff --git a/NTPClient.h b/NTPClient.h index a31d32f..839ca8e 100755 --- a/NTPClient.h +++ b/NTPClient.h @@ -25,7 +25,7 @@ class NTPClient { byte _packetBuffer[NTP_PACKET_SIZE]; - void sendNTPPacket(); + bool sendNTPPacket(); public: NTPClient(UDP& udp); From 395e90dc629d0f774ceb9f1042a7ccf063bc2994 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 12 Oct 2022 20:53:56 +0000 Subject: [PATCH 2/2] Bump geekyeggo/delete-artifact from 1 to 2 Bumps [geekyeggo/delete-artifact](https://github.com/geekyeggo/delete-artifact) from 1 to 2. - [Release notes](https://github.com/geekyeggo/delete-artifact/releases) - [Commits](https://github.com/geekyeggo/delete-artifact/compare/v1...v2) --- updated-dependencies: - dependency-name: geekyeggo/delete-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 986bda6..10abaea 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -114,7 +114,7 @@ jobs: path: ${{ env.CONFIGURATIONS_FOLDER }} - name: Remove unneeded artifact - uses: geekyeggo/delete-artifact@v1 + uses: geekyeggo/delete-artifact@v2 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }}