WebSocket client (on WiPy, ESP8266 or Unix) ?

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
ubiq_01
Posts: 26
Joined: Mon Feb 08, 2016 1:45 pm
Location: Dresden, Germany

WebSocket client (on WiPy, ESP8266 or Unix) ?

Post by ubiq_01 » Thu Sep 01, 2016 9:47 am

Did somebody work on / knows about WebSocket client code for WiPy, ESP8266 or the MicroPython Unix version?

Context is: I'd like to connect to SAP HCP IoT Services (I put a https version for doing so at https://github.com/SAP/iot-starterkit/b ... ary_get.py ) but now aim to work with wss which would give us better bandwidth efficiency and a bi-directional channel.

Maybe there is also a chance to use the https://github.com/liris/websocket-client lib that works well with standard Python?

best regards
Ralf

ubiq_01
Posts: 26
Joined: Mon Feb 08, 2016 1:45 pm
Location: Dresden, Germany

Re: WebSocket client (on WiPy, ESP8266 or Unix) ?

Post by ubiq_01 » Fri Sep 02, 2016 2:23 pm

Meanwhile I did some further checks.
- There is a "built-in" websocket module (that pfalcon wrote) - is there any further info about its usage?
- I checked the liris websocket-client lib - unfortunately it has a number of dependencies (e.g. six.py), so it might be easier to just start from e.g. a simple Arduino websocket lib like https://github.com/MORA99/Stokerbot/tre ... cketClient ? (I successfully used it with a RedBear CC3200 based module and Energia).

Any feedback is highly welcome
Ralf

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: WebSocket client (on WiPy, ESP8266 or Unix) ?

Post by pfalcon » Fri Sep 02, 2016 2:49 pm

ubiq_01 wrote: - There is a "built-in" websocket module (that pfalcon wrote) - is there any further info about its usage?
It's in "provisional" mode, and not documented, because details of the interface may change. It's otherwise works in a pretty natural way, and you got as far as the above, you won't have problem to figure out how to use it, following ESP8266 webrepl code which uses it. Note that by default that works in server mode, you may need to check client support (feel free to report any issues on github). Pure-Python client-side counterpart can be found in webrepl_cli.py from webrepl repo on github.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

ubiq_01
Posts: 26
Joined: Mon Feb 08, 2016 1:45 pm
Location: Dresden, Germany

Re: WebSocket client (on WiPy, ESP8266 or Unix) ?

Post by ubiq_01 » Fri Sep 02, 2016 2:53 pm

Many thanks! That helps!

best regards
Ralf

ubiq_01
Posts: 26
Joined: Mon Feb 08, 2016 1:45 pm
Location: Dresden, Germany

Re: WebSocket client (on WiPy, ESP8266 or Unix) ?

Post by ubiq_01 » Tue Sep 06, 2016 9:35 am

I have a 1st Websocket+TLS = wss:// interaction with the SAP IoT Services up and running on my desktop. https://twitter.com/_rac01/status/773090983630233601

I can receive data "pushed" to a device - and have to check the "upstream" (where the server complains about "the frame not being masked" still. I'll try on a WiPy next.

best regards
Ralf

ubiq_01
Posts: 26
Joined: Mon Feb 08, 2016 1:45 pm
Location: Dresden, Germany

Re: WebSocket client (on WiPy, ESP8266 or Unix) ?

Post by ubiq_01 » Tue Sep 06, 2016 1:05 pm

Meanwhile there is a 1st interaction on the WiPy as well.
https://twitter.com/_rac01/status/773133357874024448

best regards
Ralf

ubiq_01
Posts: 26
Joined: Mon Feb 08, 2016 1:45 pm
Location: Dresden, Germany

Re: WebSocket client (on WiPy, ESP8266 or Unix) ?

Post by ubiq_01 » Wed Sep 07, 2016 7:59 am

It's working now! https://twitter.com/_rac01/status/773427887701712896

Many thanks to pfalcon for the support and https://github.com/micropython/webrepl as a starting point.

For my purposes I had to modify:
- add OAuth authentication in wss setup
- use text (instead of binary) frames
- WebSocket masking mechanism for client => server communication

Great to have a way to use wss:// with WiPy and ESP8266 (in my case for IoT scenarios) now as well!

best regards
Ralf

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: WebSocket client (on WiPy, ESP8266 or Unix) ?

Post by pythoncoder » Wed Sep 07, 2016 8:28 am

It would be great if you guys with web programming experience wrote tutorials for n00bs like myself. My background is in hardware design, device drivers and assembler so internet coding presents a steep learning curve ;) Surely I'm not alone in finding it a struggle?
Peter Hinch
Index to my micropython libraries.

ubiq_01
Posts: 26
Joined: Mon Feb 08, 2016 1:45 pm
Location: Dresden, Germany

Re: WebSocket client (on WiPy, ESP8266 or Unix) ?

Post by ubiq_01 » Wed Sep 07, 2016 12:24 pm

That's quite understood.

As one resource I can refer to the SAP IoT Starterkit https://github.com/SAP/iot-starterkit that combines step by step instructions for setting up the Cloud part (which is in a free trial environment) with several (also Python) code snippets and ready-to-run applications. Some code like https://github.com/SAP/iot-starterkit/t ... y_transfer have been done and tested with exactly components as small as the WiPy or ESP8266 / Micropython in mind.

best regards
Ralf

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: WebSocket client (on WiPy, ESP8266 or Unix) ?

Post by pythoncoder » Wed Sep 07, 2016 12:35 pm

Thank you, those links look promising. I will study them properly soon. I'm keen to get MQTT running with SSL but haven't got my head round the certificate stuff...
Peter Hinch
Index to my micropython libraries.

Post Reply