# Complete project details at https://RandomNerdTutorials.com
#
# https://randomnerdtutorials.com/micropython-esp8266-deep-sleep-wake-up-sources/
# Dieses Beispiel funktioniert leider nicht, da rtc.irq anscheinend nicht unterstützt wird.
import machine
from machine import Pin
from time import sleep
from machine import RTC, Timer
led = Pin(2, Pin.OUT)
def deep_sleep(msecs):
# configure RTC.ALARM0 to be able to wake the device
rtc = machine.RTC()
rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
# set RTC.ALARM0 to fire after X milliseconds (waking the device)
rtc.alarm(rtc.ALARM0, msecs)
# put the device to sleep
machine.deepsleep()
#blink LED
led.value(1)
sleep(1)
led.value(0)
sleep(1)
# wait 5 seconds so that you can catch the ESP awake to establish a serial communication later
# you should remove this sleep line in your final script
sleep(5)
print('Im awake, but Im going to sleep')
#sleep for 10 seconds (10000 milliseconds)
deep_sleep(10000)