Giter Site home page Giter Site logo

lemariva / upyecho Goto Github PK

View Code? Open in Web Editor NEW
53.0 5.0 11.0 23 KB

Emulated Belkin WeMo device that works with Amazon Echo (Alexa) using MicroPython on an ESP32

Home Page: https://lemariva.com/blog/2017/10/micropython-wemos-and-amazon-echo-alexa

License: Apache License 2.0

Python 100.00%
esp32 micropython amazon-echo amazon-alexa ledstrip lighthouse

upyecho's Introduction

uPyEcho

Emulated Belkin WeMo device that works with Amazon Echo using MicroPython

About the repository

This repository is based on makermusings/fauxmo and it was ported to work on MicroPython. This code emulates one or more Belkin WEMO type devices in software, and allows you to control them using an Amazon Echo. The code was tested on:

  • ESP32 (WeMos board).
  • Amazon Echo Dot (2nd Generation) - revision 1.1 should work with all the versions of Amazon Echo.

You do not need to use AWS Lambda, or ngrok or open a port on your router. Amazon Echo searches for Belkin WEMO devices on the local network and using this code the WeMos board responds to the search request. For more information, please read this article.

Video

PoC

Requirements

Instructions

  • Install MicroPython on the ESP32, you can use this tutorial;
  • Modify the following lines in the boot.py
    • ssid_ = <your ssid>
    • wp2_pass = <your wpa2 password>
  • Modify the main.py file if you want to:
    • The code line
    ws2812_chain =  WS2812(ledNumber=ledNumber, brightness=100)
    defines the WS2812 LED strip. The argument ledNumber defines the size of the LED strip. In my case, I used 144 LEDs.
    • The code lines
      devices = [
          {"description": "white led",
           "port": 12340,
           "handler": rest_api_handler((255,255,255), 50)},
           ... ]
    define the devices that are going to be found by Amazon Echo. Please read this article for more information;
  • Upload the code to the WeMos board;
  • Connect the LED strip and restart the board;
  • Start a device search from Amazon Echo. You can use the Alexa application, or just say, "echo/alexa, search for new devices" and wait;
  • Say, "echo/alexa, turn on the ", it should work.

Changelog

  • Revision: 1.1 - Code cleaned and added support for Amazon Echo (2nd Generation) using this info.
  • Revision: 1.0 - Initial commit

License

  • Check files

Credits

More Info:

upyecho's People

Contributors

lemariva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

upyecho's Issues

BUG: socket collections grow unchecked

uPyEcho/main.py

Lines 298 to 302 in e09c28d

if not data:
self.poller.remove(self, self.client_sockets[fileno])
self.client_sockets[fileno].close()
else:

self.client_sockets dictionary of sockets keeps growing unchecked. You need to pop each client socket when no data is received:

self.client_sockets.pop(fileno)

Also, in the poller.remove() function you need to remove the socket from self.targets:

uPyEcho/main.py

Lines 197 to 203 in e09c28d

def remove(self, target, socket=None):
if not socket:
socket = target.sockets()
if self.use_poll:
self.poller.unregister(socket)
# dbg("remove device on fileno: %s" % socket.fileno() )
gc.collect()

self.targets.pop(socket.fileno())

Nearly there?

I'm trying to get this going on a spiram esp32 ttgo wrover module.
I have had to import a couple of different modules and change the rtc etc.
All is apparently working as I see no exception messages, and the date time displays correctly.
Goes into the main loop and displays Targets dict_keys([54, 55]) … does this mean I am actually close? I do have other Arduino fauxmo units running, but I wanted micropython running.
I shut down the other fauxmo units whilst 'finding devices' but to no luck.
Any help would be appreciated …. thanks

Author
roffey commented 15 minutes ago
now getting this reply error …
Got problem to send response function takes 1 positional arguments but 3 were given...
doing what I can with wireshark etc.... will keep plodding away, but a little help would be good :)

index out of range errors :: Devices unresponsive

I was porting uPyEcho to latest MicroPython (June 2020-- 1.12_2 ) to run on the TinPICO.

As part of that, I had to change all the references to clock.gmtime() to clock.datetime() when composing the date_str. as gmtime() is not available on my MP port.

After this format_timetuple_and_zone was hitting index out of range errors and my devices were intermittently discoverable AND always unresponsive after they did work (On and Off).

I tracked that down to changing the timetuple[6] in the day of the week section to [timetuple[4].

This is the corrected function which worked for me.

def format_timetuple_and_zone(timetuple, zone):
    return "%s, %02d %s %04d %02d:%02d:%02d %s" % (
        ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][timetuple[4]],
        timetuple[2],
        [
            "Jan",
            "Feb",
            "Mar",
            "Apr",
            "May",
            "Jun",
            "Jul",
            "Aug",
            "Sep",
            "Oct",
            "Nov",
            "Dec",
        ][timetuple[1] - 1],
        timetuple[0],
        timetuple[3],
        timetuple[4],
        timetuple[5],
        zone,
    )

I don't know why this happened. I'm not sure if the time.gmtime() on your ports of MicroPython just has different looking tuples, if the timetuple changed in MicroPython or if this was always a bug. But for me on 1.12 on the TinyPICO this works.

I thought I'd share in case others hit this this as well.

Thanks!

Nearly there?

I'm trying to get this going on a spiram esp32 ttgo wrover module.
I have had to import a couple of different modules and change the rtc etc.
All is apparently working as I see no exception messages, and the date time displays correctly.

Goes into the main loop and displays Targets dict_keys([54, 55]) … does this mean I am actually close? I do have other Arduino fauxmo units running, but I wanted micropython running.
I shut down the other fauxmo units whilst 'finding devices' but to no luck.

Any help would be appreciated …. thanks

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.