Hi,
is the time format (as in setenv(TZ,) ) with “GMT+XX” supported?
I keep trying to set my time with
void init_sntp() { if (isSet()) { ESP_LOGW(TAG, "init_sntp called although already set inited_sntp: %d", inited_sntp); } initialize_sntp(); time_t now = 0; struct tm timeinfo = {0}; int retry = 0; const int retry_count = 10; 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); } ESP_LOGI(TAG, "sntp_get_sync_status() %d", sntp_get_sync_status()); time(&now); localtime_r(&now, &timeinfo); print_now(); if (retry >= retry_count) { ESP_LOGW(TAG, "SNTP sync failed!"); } }
initializing it with:
void initialize_sntp(void) { if (inited_sntp) return; inited_sntp = true; ESP_LOGI(TAG, "Initializing SNTP to %s ", MgConfig::instance()->tz_.c_str()); //setenv("TZ", MgConfig::instance()->tz_.c_str(), 1); setenv("TZ", "CST-8", 1); tzset(); sntp_setoperatingmode(SNTP_OPMODE_POLL); sntp_setservername(0, "pool.ntp.org"); sntp_init(); }
and printing it with:
void print_now() { time_t now; char strftime_buf[64]; struct tm timeinfo; localtime_r(&now, &timeinfo); strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); ESP_LOGI(TAG, "The current date/time in %s is %s", MgConfig::instance()->tz_.c_str(), strftime_buf); }
I keep getting impossible time values like:
I (11108) time-mod: The current date/time in New York is: Thu Jan 1 00:00:00 1970
and even after going back to CST-8 and not setting the time myself it still seems wrong, though with CST i just get epoch ß and with GMT+2 (which is what my config object returns) i get some bizzare values that jump around from 1901 to 2004 and back again.
Did i kill something with GMT ? is that supported ? how can i get this to function properly ?
sntp_sync_time just returns 0 so i really do not know what’s wrong