#include
"STM32LowPower.h"
#include
<STM32RTC.h>
STM32RTC
&
rtc
=
STM32RTC::getInstance();
const
byte
seconds
=
0
;
const
byte
minutes
=
0
;
const
byte
hours
=
16
;
const
byte
day
=
20
;
const
byte
month
=
4
;
const
byte
year
=
22
;
void
alarmMatch(
void
*
data);
void
setup
()
{
Serial.begin
(
115200
);
rtc.begin();
rtc.setTime(hours, minutes, seconds);
rtc.setDate(day, month, year);
delay
(
1000
);
String someRandomData
=
"www.mischianti.org"
;
LowPower.begin();
LowPower.enableWakeupFrom(
&
rtc, alarmMatch,
&
someRandomData);
rtc.setAlarmDay(day);
rtc.setAlarmTime(
16
,
0
,
10
,
0
);
rtc.enableAlarm(rtc.MATCH_DHHMMSS);
Serial.printf(
"Now is %02d/%02d/%02d %02d:%02d:%02d.%03d and we set the wake at 16:10! So wait 10secs! \n"
,
rtc.getDay(), rtc.getMonth(), rtc.getYear(),
rtc.getHours(), rtc.getMinutes(), rtc.getSeconds(), rtc.getSubSeconds());
Serial.println
(
"Deep Sleep!"
);
delay
(
1000
);
LowPower.deepSleep();
}
void
loop
()
{
Serial.printf(
"%02d/%02d/%02d "
, rtc.getDay(), rtc.getMonth(), rtc.getYear());
Serial.printf(
"%02d:%02d:%02d.%03d\n"
, rtc.getHours(), rtc.getMinutes(), rtc.getSeconds(), rtc.getSubSeconds());
delay
(
1000
);
}
void
alarmMatch(
void
*
data)
{
String myData
=
*
(String
*
)data;
Serial.println
(
"Alarm Match!"
);
Serial.println
(myData);
}