Wake up in specific date with internal RTC

User avatar
urbanze
Posts: 295
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Wake up in specific date with internal RTC

Postby urbanze » Mon Aug 20, 2018 11:59 pm

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"?

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: Wake up in specific date with internal RTC

Postby ESP_igrr » Tue Aug 21, 2018 6:26 am

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);

User avatar
urbanze
Posts: 295
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Re: Wake up in specific date with internal RTC

Postby urbanze » Tue Aug 21, 2018 6:44 pm

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?

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 103 guests