diff --git a/src/modems/DigiXBeeWifi.cpp b/src/modems/DigiXBeeWifi.cpp index 21a6d812b..47a7b4896 100644 --- a/src/modems/DigiXBeeWifi.cpp +++ b/src/modems/DigiXBeeWifi.cpp @@ -405,15 +405,15 @@ uint32_t DigiXBeeWifi::getNISTTime(void) { // Wait up to 5 seconds for a response if (connectionMade) { uint32_t start = millis(); - while (gsmClient && gsmClient.available() < 4 && + while (gsmClient && gsmClient.available() < NIST_RESPONSE_BYTES && millis() - start < 5000L) { // wait } if (gsmClient.available() >= 4) { MS_DBG(F("NIST responded after"), millis() - start, F("ms")); - byte response[4] = {0}; - gsmClient.read(response, 4); + byte response[NIST_RESPONSE_BYTES] = {0}; + gsmClient.read(response, NIST_RESPONSE_BYTES); gsmClient.stop(); return parseNISTBytes(response); } else { diff --git a/src/modems/LoggerModemMacros.h b/src/modems/LoggerModemMacros.h index 1d260bb87..78d2fa138 100644 --- a/src/modems/LoggerModemMacros.h +++ b/src/modems/LoggerModemMacros.h @@ -458,13 +458,16 @@ * @brief The port hosting the NIST "time" protocol (37) */ #define TIME_PROTOCOL_PORT 37 +/** + * @brief The size of the NIST response from the "time" protocol, in bytes. + */ +#define NIST_RESPONSE_BYTES 4 -// Try up to 4 NIST IP addresses attempting to get a timestamp from NIST #if !defined NIST_SERVER_RETRYS || defined(DOXYGEN) /** * @brief The number of retry attempts when connecting to the NIST server. */ -#define NIST_SERVER_RETRYS 4 +#define NIST_SERVER_RETRYS 12 #endif // NIST_SERVER_RETRYS /** @@ -511,11 +514,11 @@ gsmClient.available() < NIST_SERVER_RETRYS && \ millis() - start < 5000L) {} \ \ - if (gsmClient.available() >= 4) { \ + if (gsmClient.available() >= NIST_RESPONSE_BYTES) { \ MS_DBG(F("NIST responded after"), millis() - start, \ F("ms")); \ - byte response[4] = {0}; \ - gsmClient.read(response, 4); \ + byte response[NIST_RESPONSE_BYTES] = {0}; \ + gsmClient.read(response, NIST_RESPONSE_BYTES); \ if (gsmClient.connected()) gsmClient.stop(); \ return parseNISTBytes(response); \ } else { \