Continuing a Question asked few days ago, answered by Edgar, a new question has rised:
My goal was using a past time_t
value, and convert it into a struct tm
variable in order to use it, part as a Char
to print a readable text and some for logic queries.
At start NTP is configured as:
void myIOT32::startNTP(const int gmtOffset_sec = 2 * 3600, const int daylightOffset_sec = 3600, const char *ntpServer = "pool.ntp.org")
{
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
}
and every-time I need to get epoch and or struct tm
of current time I call this function
void myIOT32::getTime()
{
int a = 0;
while (a < 3)
{
if (getLocalTime(&timeinfo))
{
delay(100);
time(&epoch_time);
}
a++;
}
BUT, when using the following function I get not GMT (+3) reference as needed :
struct tm *myIOT32::convEpoch(time_t in_time)
{
struct tm *convTime = gmtime(&in_time);
//char time_char[40];
//sprintf(time_char, "%04d-%02d-%02d %02d:%02d:%02d", convTime->tm_year + 1900, convTime->tm_mon + 1, convTime->tm_mday,
convTime->tm_hour, convTime->tm_min, convTime->tm_sec);
return convTime;
}
Meaning I get to correct epoch time, but strcut tm
is 3 hrs earlier ( and no, I do not want to hard-code +3
... )
start NTP
was executed ?TimeLib
... since in example called "simpleTime" for ESP32 used dates that way ( and not as in ESP8266), so I guessed it is a compatibility issue.