Giter Club home page Giter Club logo

uwebsockets's Introduction

Micropython websockets (esp8266 implementation)

An implementation of websockets for the ESP8266 (client only ATM). This is a work in progress, some of which might move into the modwebsocket C module that's built into micropython, however that's incomplete, and the handshaking isn't standard-compliant.

There's no asyncio on the esp8266 (today) but I'd like to build something that looks for all intents and purposes like a asyncio Protocol using the socket receive handler it does have.

"Screenshot"

$ pip install adafruit-ampy
$ ampy mkdir uwebsockets
$ ampy put uwebsockets/protocol.py uwebsockets/protocol.py
$ ampy put uwebsockets/client.py uwebsockets/client.py
$ ampy run example/client.py
> esp8266 1.5.4(baaeaebb) v1.8.3-80-g1f61fe0-dirty on 2016-08-31 ESP module with ESP8266
< Hello esp8266 1.5.4(baaeaebb) v1.8.3-80-g1f61fe0-dirty on 2016-08-31 ESP module with ESP8266!
$ pip install websockets
$ python example/server.py
Connection from ('192.168.1.11', 1883)
< esp8266 1.5.4(baaeaebb) v1.8.3-80-g1f61fe0-dirty on 2016-08-31 ESP module with ESP8266
> Hello esp8266 1.5.4(baaeaebb) v1.8.3-80-g1f61fe0-dirty on 2016-08-31 ESP module with ESP8266!

Minimal example client against 'ws://echo.websocket.org/'

$ webrepl_client.py 192.168.3.1
Password: 

WebREPL connected
>>> 
>>> 
MicroPython v1.9.4-272-g46091b8a on 2018-07-18; ESP module with ESP8266
Type "help()" for more information.
>>> import echo_websocket_org
The quick brown fox jumps over the lazy dog

>>> 
### closed ###
$ 
$ cat echo_websocket_org.py 
import uwebsockets.client
websocket = uwebsockets.client.connect("ws://echo.websocket.org/")
mesg = "The quick brown fox jumps over the lazy dog"
websocket.send(mesg + "\r\n")
resp = websocket.recv()
print(resp)
assert(mesg + "\r\n" == resp)
$ 

Micropython Socket.io

An implementation of socket.io and engine.io for the ESP8266 (client only ATM). This is a work in progress and has only been tested against Flask-SocketIO.

There's no asyncio on the esp8266 (today) but I'd like to build something that looks for all intents and purposes like the socket.io web API. At the moment this means its own event loop + lots of timeouts.

An interesting example client is this OpsGenie bridge.

Compatibility

You might need to bake this code into your firmware to use it. You also need to bake in the logging module. Finally to run the unix port you need to patch your micropython to support socket.settimeout.

uwebsockets's People

Contributors

adrianalin avatar danni avatar fakufaku 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.