Page 1 of 2

WebSocket client (on WiPy, ESP8266 or Unix) ?

Posted: Thu Sep 01, 2016 9:47 am
by ubiq_01
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

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

Posted: Fri Sep 02, 2016 2:23 pm
by ubiq_01
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

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

Posted: Fri Sep 02, 2016 2:49 pm
by pfalcon
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.

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

Posted: Fri Sep 02, 2016 2:53 pm
by ubiq_01
Many thanks! That helps!

best regards
Ralf

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

Posted: Tue Sep 06, 2016 9:35 am
by ubiq_01
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

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

Posted: Tue Sep 06, 2016 1:05 pm
by ubiq_01
Meanwhile there is a 1st interaction on the WiPy as well.
https://twitter.com/_rac01/status/773133357874024448

best regards
Ralf

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

Posted: Wed Sep 07, 2016 7:59 am
by ubiq_01
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

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

Posted: Wed Sep 07, 2016 8:28 am
by pythoncoder
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?

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

Posted: Wed Sep 07, 2016 12:24 pm
by ubiq_01
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

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

Posted: Wed Sep 07, 2016 12:35 pm
by pythoncoder
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...