Hello Felix,
Thank you very much for your reply.
I updated the code according to your suggestion.
- I know the actual time so I set the actual date and time of RTC.
rtc_date_t RTCDate;
rtc_time_t RTCtime;
RTCDate.year = year();
RTCDate.mon = month();
RTCDate.day = day();
M5.RTC.setDate(&RTCDate);
RTCtime.hour = hour();
RTCtime.min = minute();
RTCtime.sec = second();
M5.RTC.setTime(&RTCtime);
Serial.print("\n Actual RTC date and time =>" + String(RTCDate.day) + "-" + String(RTCDate.mon) + "-" + String(RTCDate.year) + " " + String(RTCtime.hour) + ":" + String(RTCtime.min) + ":" + String(RTCtime.sec) );
- I also know the sleep duration in secs. for example
30 minutes (1800 secs)
. So I added these secs into the current time to get the wakeup time in the future.
int nextRereshTimeInSecs = now() + 1800;
setTime(nextRereshTimeInSecs);
- Then I set the alarm using
setAlarmIRQ(const rtc_date_t &date, const rtc_time_t &time)
and shut down the M5stack-paper.
rtc_date_t wakeupDate;
rtc_time_t wakeupTime;
int currentYear = year();
int8_t int8_year = currentYear % 100;
int8_t int8_month = month();
int8_t int8_day = day();
// Populate rtc_date_t structure
wakeupDate.year = int8_year ;
wakeupDate.mon = int8_month ;
wakeupDate.day = int8_day;
int8_t int8_hour = hour();
int8_t int8_minute = minute();
int8_t int8_second = second();
// Populate rtc_time_t structure
wakeupTime.hour = int8_hour;
wakeupTime.min = int8_minute;
wakeupTime.sec = int8_second;
Serial.print("\n Future RTC date and time =>" + String(wakeupDate.day) + "-" + String(wakeupDate.mon) + "-" + String(wakeupDate.year) + " " + String(wakeupTime.hour) + ":" + String(wakeupTime.min) + ":" + String(wakeupTime.sec) );
delay(300);
M5.RTC.clearIRQ();
M5.RTC.setAlarmIRQ(wakeupDate, wakeupTime);
delay(10);
M5.shutdown();
Currently, I am testing it with the sleep duration of 30 minutes and it looks like working. I will test it for more than 4 hours tonight.
The question is that, do I have to use
M5.shutdown( wakeupDate, wakeupTime)
OR
is it OK what I am currently using
M5.RTC.setAlarmIRQ(wakeupDate, wakeupTime);
M5.shutdown();