Rolling 2020-12-02

This commit is contained in:
jomjol
2020-12-02 07:50:51 +01:00
parent ed3226e3a0
commit f6f3e2377e
8 changed files with 1184 additions and 19 deletions

View File

@@ -48,18 +48,7 @@ std::string gettimestring(const char * frm)
time_t now;
struct tm timeinfo;
time(&now);
localtime_r(&now, &timeinfo);
// Is time set? If not, tm_year will be (1970 - 1900).
if (timeinfo.tm_year < (2016 - 1900)) {
ESP_LOGI(TAG, "Reboot - Connecting to WiFi and getting time over NTP.");
obtain_time();
// update 'now' variable with current time
time(&now);
}
char strftime_buf[64];
// setenv("TZ", "UTC-2", 1);
// tzset();
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), frm, &timeinfo);
@@ -119,6 +108,8 @@ static void obtain_time(void)
struct tm timeinfo = {};
int retry = 0;
const int retry_count = 10;
time(&now);
localtime_r(&now, &timeinfo);
while (sntp_get_sync_status() == SNTP_SYNC_STATUS_RESET && ++retry < retry_count) {
ESP_LOGI(TAG, "Waiting for system time to be set... (%d/%d)", retry, retry_count);
vTaskDelay(2000 / portTICK_PERIOD_MS);