I´m trying to build something like a data logger that executes some lines of code, then goes into sleep/deepsleep mode and wakes up after a defined time period to start again.
My code below is based on the machine.RTC.alarm sample with repeat set to True. As expected the WiPy goes into sleep mode for the first 10 seconds, than wakes up (the heartbeat led flashes a few times very quickly) and stops the script execution without any error message. The code within alarm_handler is not executed. Even with pass as single command within alarm_handler no periodic alarm happens.
Code: Select all
import machine
from machine import RTC
rtc = machine.RTC() # init with default time and date
def alarm_handler (rtc_o):
# do something...
f = open('/flash/test.txt', 'a')
f.write('.')
f.close()
# create a RTC alarm that expires after 10 seconds
rtc.alarm(time=10000, repeat=True)
# enable RTC interrupts
rtc_i = rtc.irq(trigger=RTC.ALARM0, handler=alarm_handler, wake=machine.SLEEP)
# go into suspended mode
machine.sleep()