I need to create a converter from epoch time stored in a time_t
variable, to a struct tm
variable, in order to check / create a certain task every hour or a day. This function should get also a past time_t
for other uses.
Converting function, inside a library, works OK ( last two lines are for verification purposes, meaning conversion was done as expected ):
void myIOT32::convEpoch(time_t in_time, struct tm *convTime)
{
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);
Serial.print(" from funct: ");
Serial.println(time_char);
Now, when calling it from my code and try to use time tm
var, it causes the code to crash. In code below, I just try to print it to console:
void sendnewNotif()
{
struct tm *newtime;
time_t t=182423032;
iot.convEpoch(t, newtime); // <--- Using the conversion
char timeStamp[50];
// Serial.print(newtime->tm_year);
}
What may be the problem ?
Guy
struct tm newtime;
to alocate on stack.struct tm *newtime
is a pointer to nowhere