In my code upon wake up I want to have the esp retrieve time using sntp. The sync works perfectly the first time as it updates from 1970 to 2019, althought I have no idea what to make the condition for subsequent sync's to allow it to resync.
Code: Select all
time_t now = 0;
struct tm timeinfo = { 0 };
int retry = 0;
const int retry_count = 10;
while(timeinfo.tm_year < (2019 - 1900) && ++retry < retry_count) {
ESP_LOGI(TAG, "Waiting for system time to be set... (%d/%d)", retry, retry_count);
vTaskDelay(2000 / portTICK_PERIOD_MS);
time(&now);
localtime_r(&now, &timeinfo);
}
Thanks in advance for any help!