Skip to content

Commit

Permalink
ESP32 ensure SNTP sync enabled before waiting
Browse files Browse the repository at this point in the history
Signed-off-by: Sara Damiano <[email protected]>
  • Loading branch information
SRGDamia1 committed Feb 2, 2025
1 parent 3428675 commit e630e5f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/TinyGsmClientESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,16 @@ class TinyGsmESP32 : public TinyGsmEspressif<TinyGsmESP32>,
}

bool waitForTimeSync(int timeout_s = 120) {
// if we're not connected, we'll never get the time
if (!isNetworkConnected()) { return false; }
// if SNTP sync isn't enabled, we won't have the time
// NOTE: We don't actually enable the time here, because doing so would
// change any user settings for the timezone and time servers.
sendAT(GF("+CIPSNTPCFG?"));
int8_t is_enabled = streamGetIntBefore(',');
waitResponse(); // returns OK
if (!is_enabled) { return false; }
// if we're sure we should be able to get the time, wait for it
uint32_t start_millis = millis();
while (millis() - start_millis < static_cast<uint32_t>(timeout_s) * 1000) {
uint32_t modem_time = getNetworkEpoch();
Expand Down

0 comments on commit e630e5f

Please sign in to comment.