Konubinix' opinionated web of thoughts

Switch for Ventilating a Room Using a MCU on Micropython

Fleeting

Using the Adafruit Feather HUZZAH with ESP8266 and micropython.

I could do the same thing using the dedicated remote controls, but they are not attractive enough et it is a good opportunity to try the deep sleep mode and espnow.

a first prototype

from time import sleep

import machine
import network
import requests
from machine import Pin

led = Pin(2, Pin.OUT)
wlan = network.WLAN(network.STA_IF)
wlan.active(True)


def say(message):
    print(message)
    requests.post("http://home:9705/test", data=message)


if machine.reset_cause() == machine.DEEPSLEEP_RESET:
    say('woke from a deep sleep')
else:
    say('power on or hard reset')


def deep_sleep(msecs):
    rtc = machine.RTC()
    rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
    rtc.alarm(rtc.ALARM0, msecs)
    machine.deepsleep()


led.value(1)
sleep(1)
led.value(0)

say("Waiting for 5s before going to deep sleep")

sleep(5)

say('Going to deep sleep for 10s, good night...')

deep_sleep(10000)

I tried waiting for the RTC to wake it up, waking it up myself using a push button and reset it before it goes to deep sleep

That is encouraging so far.