Giter VIP home page Giter VIP logo

upython-relay-timer's Introduction

MicroPython Relay/Sonoff countdown timer

Countdown timer for a Sonoff switch or a random relay, written in MicroPython.

Features

  • Simple countdown timer
  • Relay is off when the device is powered. Press the button to add 30 seconds, or a different customizable time increment
  • Hold the button to turn it off
  • Connect it to Wi-Fi to control it using a simple web UI

Screenshot

Edit the variables at the beginning of the script to customize.

Then, in your boot.py add the following code to run it:

import timer
timer.main()

DO NOT EXPOSE IT TO THE PUBLIC INTERNET!

The web server is extremely basic and intended to be used in private networks only!

Requires uasyncio!

Uasyncio is included in MicroPython builds only for ESP8266/ESP32 boards with 1MB or more flash.

For ESP8266 boards with 512KB of flash such as the Sonoff Basic, you need to rebuild MicroPython yourself, or you can use my build here (MicroPython v1.13): esp8266-512KB-uasyncio.bin

Build instructions

I created a patch that disables a few unused drivers, TLS supports (it's not very good anyway) and the WebREPL to reclaim some space, and adds the uasyncio module. You can use rshell as a replacement for the WebREPL to edit the files.

Building it is just a matter of running the following steps on GNU/Linux (requires docker, git and esptool).

You can copy the script into the ports/esp8266/modules directory to pre-freeze it and include it in the firmware, but you need to reflash it every time you want to perform any changes.

git clone https://github.com/micropython/micropython.git --recursive
git clone https://github.com/micropython/micropython-lib.git --recursive
git clone https://github.com/Depau/upython-relay-timer.git
cd micropython
git am < ../upython-relay-timer/0001-Slim-ESP8266-with-uasyncio-built-in.patch
alias esp='docker run --rm -v $HOME:$HOME -u $(id -u) -w $(pwd) larsks/esp-open-sdk'
esp make -j12 -C ports/esp8266 BOARD=GENERIC_SLIM

Flashing on Sonoff Basic or ESP8266 with <= 512KB flash

If you built it yourself the firmware will be located at ports/esp8266/build-GENERIC_SLIM/firmware-combined.bin, otherwise you can use my build.

Follow the official MicroPython instructions.

Here is also a guide to flash a Sonoff by soldering the UART header, the header might be in a slightly different location but otherwise it's the same.

esptool.py --port /dev/ttyUSBx erase_flash
esptool.py --port /dev/ttyUSBx --baud 460800 write_flash --flash_size=detect 0 ports/esp8266/build-GENERIC_SLIM/firmware-combined.bin

Other boards

If you are using an ESP8266 with 1MB or more of flash, there's no need to create a custom build. If you're using an ESP32 with 512KB, you're on your own, read my patch and perform the same things on the ESP32 port.

In short you can copy the 1MB build configurations, make it use the 512KB linker script and remove unnecessary modules such as NeoPixel driver, WebREPL, ussl (basic TLS implementation), etc.

License

GNU Affero General Public License 3.0

upython-relay-timer's People

Contributors

depau avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.