You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Simple example of uasyncio WebSocket Server (secure - with SSL) #8177
I would like a simple example of uasyncio WebSocket Server (secure - with SSL). I see that there is a official uwebsocket module implemented on MicroPython.
>>> import os
>>> os.uname()
(sysname='esp32', nodename='esp32', release='1.17.0', version='v1.17 on 2021-09-02', machine='ESP32 module (spiram) with ESP32')
>>> import uwebsocket
>>>
Look at Picoweb. It uses uasyncio by Paul Sokolovsky. https://github.com/pfalcon/picoweb
For ssl, I don't know. But it has an example with basic authentication.
Look at Picoweb. It uses uasyncio by Paul Sokolovsky. https://github.com/pfalcon/picoweb For ssl, I don't know. But it has an example with basic authentication.
The Picoweb do not support websocket. Even uasyncio on PicoWeb is old, it is not the official v3 uasyncio compatible, but it is good start point.
The https://github.com/jczic/MicroWebSrv use WebSocket, but is not official uwebsocket module - it wrote their own websocket module. And is better (if is possible) to use the official, for compatibility and so on.
This project https://github.com/Carglglz/upydev/tree/master/upyutils has a WebREPL example working with SSL using the official uwebsocket module - that is great. This project was put as a PR (#5611) to support SSL in the official WebREPL, but I do not know why still not was merged, after two years.
I need just to know now how to add uasyncio on that WebREPL + SSL example.
@beyonlo FYI with the latest changes to #8968 I'm able to run a microdot_async + tls (https) server and WebREPL + tls (wss) + aiorepl at the same time, so I think the uasyncio WebSocket Server (secure - with SSL) should be possible too. 👍🏼
so I think the uasyncio WebSocket Server (secure - with SSL) should be possible too. 👍🏼
Sorry for my ignorance, but think that already working on the Microdot, like as show this example echo_async_tls.py working with this index.html that use wss (WebSocket Secure Server).
Please, let me know what I missing. I'm a bit confuse now: how that (uasyncio WebSocket Server (secure - with SSL)) already working on Microdot if the #8968 is a new implementation to have that working?
Would appreciate it if you test it and provide feedback. Note that the async support cannot currently be used with MicroPython, since uasyncio does not have the necessary support
Well, with the latest changes to #8968 the async support is enabled, so those examples will work in MicroPython too. 😄
@Carglglz Ohh, you are right, that echo_async_tls.py do not works with MicroPython. As I still developing using as base example just the echo_async.py (WebSocket Server without SSL) and just when the entire application will be stable that I was thinking do add the ssl, that was the reason that I never had tested the echo_async_tls.py on the MicroPython.
Would appreciate it if you test it and provide feedback. Note that the async support cannot currently be used with MicroPython, since uasyncio does not have the necessary support
Yes, I remember now about that moment. Maybe a good idea, as suggstion, is @miguelgrinberg add a note in the that README.md (inside tls examples) talking about that the echo_async_tls.py works (for now :) ) just on the CPython.
Well, with the latest changes to #8968 the async support is enabled, so those examples will work in MicroPython too. smile
Excellent, so maybe sooner the echo_async_tls.py will works on MicroPython as well :)
Activity
Tangerino commentedon Jan 16, 2022
You can look here. Not sure about quality, never used.
beyonlo commentedon Jan 16, 2022
@Tangerino
That use thread, not uasyncio.
bazooka07 commentedon Jan 19, 2022
Look at Picoweb. It uses uasyncio by Paul Sokolovsky.
https://github.com/pfalcon/picoweb
For ssl, I don't know. But it has an example with basic authentication.
beyonlo commentedon Jan 19, 2022
Hello @bazooka07
The Picoweb do not support websocket. Even uasyncio on PicoWeb is old, it is not the official v3 uasyncio compatible, but it is good start point.
The https://github.com/jczic/MicroWebSrv use WebSocket, but is not official
uwebsocketmodule - it wrote their own websocket module. And is better (if is possible) to use the official, for compatibility and so on.This project https://github.com/Carglglz/upydev/tree/master/upyutils has a WebREPL example working with SSL using the official uwebsocket module - that is great. This project was put as a PR (#5611) to support SSL in the official WebREPL, but I do not know why still not was merged, after two years.
I need just to know now how to add uasyncio on that WebREPL + SSL example.
QGB commentedon Oct 6, 2022
Carglglz commentedon Dec 22, 2022
@beyonlo FYI with the latest changes to #8968 I'm able to run a
microdot_async + tls (https)server andWebREPL + tls (wss) + aioreplat the same time, so I think theuasyncio WebSocket Server (secure - with SSL)should be possible too. 👍🏼beyonlo commentedon Dec 23, 2022
@Carglglz Excellent!
Sorry for my ignorance, but think that already working on the Microdot, like as show this example echo_async_tls.py working with this index.html that use
wss(WebSocket Secure Server).Please, let me know what I missing. I'm a bit confuse now: how that (uasyncio WebSocket Server (secure - with SSL)) already working on Microdot if the #8968 is a new implementation to have that working?
Thank you in advance!
Carglglz commentedon Dec 24, 2022
@beyonlo I think those examples only work with CPython at the moment?, unless I'm missing something in that example
Right now MicroPython
sslmodule has noSSLContext, and inapp.runThis calls
which calls
And if you look at
asyncio.start_serverin MicroPythonextmod/uasyncio/stream.pythere is nossloptionAlso this comment from @miguelgrinberg in the issue you opened in #34
Well, with the latest changes to #8968 the async support is enabled, so those examples will work in MicroPython too. 😄
beyonlo commentedon Dec 24, 2022
@Carglglz Ohh, you are right, that echo_async_tls.py do not works with MicroPython. As I still developing using as base example just the echo_async.py (WebSocket Server without SSL) and just when the entire application will be stable that I was thinking do add the ssl, that was the reason that I never had tested the echo_async_tls.py on the MicroPython.
Yes, I remember now about that moment. Maybe a good idea, as suggstion, is @miguelgrinberg add a note in the that README.md (inside tls examples) talking about that the echo_async_tls.py works (for now :) ) just on the CPython.
Excellent, so maybe sooner the echo_async_tls.py will works on MicroPython as well :)
Thank you for the explanation!
Merge pull request micropython#8177 from weblate/weblate-circuitpytho…
dpgeorge commentedon Dec 14, 2023
Asyncio now supports SSL server and client mode. So that's the first and main step to getting secure WebSockets.
Josverl commentedon Mar 19, 2026
Closing as the question has been answered and the conversation appears to have stopped.
Please feel free to reopen with additional information or questions as needed.