I tried setting my SNTP to "GMT+2" and now i get nothing in response (even when synced) then 0.
I use this for init:
Code: Select all
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","GMT+2", 1);
setenv("TZ", "EST5EDT", 1);
tzset();
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, "pool.ntp.org");
sntp_init();
}
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;
int status = sntp_get_sync_status();
while (status == SNTP_SYNC_STATUS_RESET && ++retry < retry_count)
{
status = sntp_get_sync_status();
ESP_LOGI(TAG, "Waiting for system time to be set... (%d/%d) status: %d", retry, retry_count, status);
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
ESP_LOGI(TAG, "sntp_get_sync_status() %d", status);
time(&now);
localtime_r(&now, &timeinfo);
print_now();
if (retry >= retry_count)
{
ESP_LOGW(TAG, "SNTP sync failed!");
}
}
and in a seperate task i call indefinetly :
Code: Select all
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);
timeval t = {};
sntp_sync_time(&t);
ESP_LOGI(TAG, " %ld", t.tv_sec);
}
but all i get is 0
The time seems to be synchronized since the loop from init breaks on mostly the second try, but i just get very wrong values:
I (602729) time-mod: The current date/time in GMT+2 is Tue Jan 6 15:24:44 2004
I (602729) time-mod: 0
I (602769) time-mod: The current date/time in GMT+2 is Wed Dec 31 19:00:00 1969
can anyone help me with this ?