lose RTC after restart (no battery)

Viewed 12

in the ESP-IDF doc about RTC, it says:

This timer allows time keeping in various sleep modes, and can also persist time keeping across any resets

I added the below lines to my main function to test it, but every time after rebooting the ESP(not a hard reset), Each time the code inside the if block is executed.

  struct timeval current_time;
  // printf("seconds : %ld\nmicro seconds : %ld", current_time.tv_sec, current_time.tv_usec);
  struct timeval d_time;
  d_time.tv_sec = 1000;
  d_time.tv_usec = 120;

  struct timezone tz;
  gettimeofday(&current_time, NULL);

  if (current_time.tv_sec < 100) {
    tz.tz_minuteswest = 210;
    tz.tz_dsttime = DST_NONE;
    settimeofday(&d_time, &tz);
  }

so, what should I do to make it work, I couldn't the problem. thank you.

0 Answers
Related