Page 1 of 1

Wake up in specific date with internal RTC

Posted: Mon Aug 20, 2018 11:59 pm
by urbanze
With the internal RTC, we can easily set a date and keep it updated automatically and smoothly in the sleep cycles with the functions of settimeofday() and etc...

But how to use that date to wake the microcontroller? I'm using archaic and less accurate methods than directly using the RTC value which consists of accounts for calculating the total sleep time (discounting code execution times and boot times).

For example use something like:

Code: Select all

esp_deep_sleep_to_date(1534898687);
This would wake up the microcontroller exactly on the date specified in UNIX/POSIX, which is kept automatically by the internal RTC and would be very interesting. The simple method would simply subtract the dates, however, I think you can have something more efficient. Is this the only method or is there something more "precise and sophisticated"?

Re: Wake up in specific date with internal RTC

Posted: Tue Aug 21, 2018 6:26 am
by ESP_igrr
Would something like this work?

Code: Select all

time_t timestamp;
// Use mktime or other function to convert date to Unix timestamp. E.g.:
struct tm wakeup_time = {
  .tm_year = year - 1900,
  .tm_mon = month,
  .tm_mday  = day,
};
timestamp = mktime(&wakeup_time);
// sleep until that time
esp_deep_sleep((timestamp - time(NULL)) * 1000000);

Re: Wake up in specific date with internal RTC

Posted: Tue Aug 21, 2018 6:44 pm
by urbanze
It is the way I imagined...

1. About the 5% drift is correct to say that without the boot calibration the drift tends to 5% and with a higher calibration, tends to 0%?

2. With 15k cycles to calibrate, I get ~0.6% of drift. To what extent is it worth increasing the calibration cycles? Is it a linear function (the more calibration, the more precise) or up to a certain value, there is not much difference? How can I decrease internal RTC drift?