ezTime icon indicating copy to clipboard operation
ezTime copied to clipboard

time() is not updated - manually call settimeofday()

Open montgomeryb opened this issue 4 years ago • 0 comments

I was using an example snippet of code to make an https call. The example had a different (less suited for me) example of sntp to set the time. Removing that and using eztime, it was failing saying the certificate was not yet valid. Even though now() returned the correct time, time(nullptr) did not. This may be as designed.

It took me quite a while to find the settimeofday method. Initially that failed because I was passing a timezone. I believe that is now deprecated and it was only after trying later with that as NULL that I could set the time and the certificates were now accepted.

      timeval tv = { now(), 0 };
      //int settimeofday(const struct timeval *tv, const struct timezone *tz);
      int i = settimeofday(&tv, NULL);      
      Serial.printf("Trying time, calling settimeofday return %d time()returns %ld. now() is %ld\n", i, time(nullptr), now());

montgomeryb avatar Jun 09 '20 18:06 montgomeryb