Skip to content

Commit fafd1c6

Browse files
committed
Vovaman#4 realized
1 parent c142c5a commit fafd1c6

File tree

4 files changed

+35
-29
lines changed

4 files changed

+35
-29
lines changed

HISTORY.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
0.1.6
1+
0.1.8
22
-----
3-
First release.
3+
Partial support for wss protocol is added.
4+
Author: [huytranle](https://github.com/huytranle)
5+
> :warning: **Disclaimer!** Server and client certificates verification
6+
> is not supported in this version.
7+
> Waiting for new micropython release...
48
59
0.1.7
610
-----
7-
Websocket can send custom headers to server in ``handshake`` function. Author: [pluzmedia](https://github.com/pluzmedia)
11+
Websocket can send custom headers to server in ``handshake`` function. Author: [pluzmedia](https://github.com/pluzmedia)
12+
13+
0.1.6
14+
-----
15+
First release.

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
# micropython-async_websocket_client
2-
This module is designed for ESP32 (and other) controllers.
3-
Goal: create and keep alive connection channel with websocket server.
4-
You may send captured data from controlled devices through this channel to server and accept managing signals on your controller.
5-
This data channel works as background task while main control cycle is running too.
2+
This module is designed for ESP32 (and other) controllers.
3+
Goal: create and keep alive connection channel with websocket server.
4+
You may send captured data from controlled devices through this channel to server and accept managing signals on your controller.
5+
This data channel works as background task while main control cycle is running too.
66
The break of websocket channel doesn't corrupt main cycle of control.
77

8-
This project based on:
9-
https://github.com/danni/uwebsockets
8+
This project based on:
9+
https://github.com/danni/uwebsockets
1010
https://github.com/peterhinch/micropython-async
1111

1212
**My gratitudes to authors**.
1313

1414
# requirements
15-
This module is designed and tested on [ESP32S-WROOM-32](https://ru.wikipedia.org/wiki/%D0%A4%D0%B0%D0%B9%D0%BB:ESP32_Espressif_ESP-WROOM-32_Dev_Board.jpg).
16-
Development and tests were done based on [esp32-20220117-v1.18.bin](https://micropython.org/resources/firmware/esp32-20220117-v1.18.bin).
15+
This module is designed and tested on [ESP32S-WROOM-32](https://ru.wikipedia.org/wiki/%D0%A4%D0%B0%D0%B9%D0%BB:ESP32_Espressif_ESP-WROOM-32_Dev_Board.jpg).
16+
Development and tests were done based on [esp32-20220618-v1.19.1.bin](https://micropython.org/resources/firmware/esp32-20220618-v1.19.1.bin).
1717

1818
# installation
1919
<details>
2020
<summary>Run this commands on your controller:</summary>
2121

22-
You have to reflash your board with [micropython](https://micropython.org/).
23-
Details are explained in https://github.com/Vovaman/start_ESP32_with_micropython.
24-
You may use VSCode as explained in link above or use `picocom` tool (also explained) to connect your board and run python console (REPL) on it.
22+
You have to reflash your board with [micropython](https://micropython.org/).
23+
Details are explained in https://github.com/Vovaman/start_ESP32_with_micropython.
24+
You may use VSCode as explained in link above or use `picocom` tool (also explained) to connect your board and run python console (REPL) on it.
2525
So, after you are in your board...
2626
</details>
2727

@@ -34,6 +34,6 @@ Development and tests were done based on [esp32-20220117-v1.18.bin](https://micr
3434
>>> upip.install('micropython-async-websocket-client')
3535
```
3636

37-
All needed dependencies are in esp32-20220117-v1.18.bin.
37+
All needed dependencies are in esp32-20220618-v1.19.1.bin.
3838
# example
3939
Sample using of this module is in https://github.com/Vovaman/example_async_websocket.

async_websocket_client/ws.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,14 @@ def urlparse(self, uri):
4848
"""Parse ws or wss:// URLs"""
4949
match = URL_RE.match(uri)
5050
if match:
51-
protocol = match.group(1)
52-
host = match.group(2)
53-
port = match.group(3)
54-
path = match.group(4)
55-
56-
if protocol == 'wss':
57-
if port is None:
58-
port = 443
59-
elif protocol == 'ws':
60-
if port is None:
61-
port = 80
62-
else:
51+
protocol, host, port, path = match.group(1), match.group(2), match.group(3), match.group(4)
52+
53+
if protocol not in ['ws', 'wss']:
6354
raise ValueError('Scheme {} is invalid'.format(protocol))
6455

56+
if port is None:
57+
port = (80, 443)[protocol == 'wss']
58+
6559
return URI(protocol, host, int(port), path)
6660

6761
async def a_readline(self):
@@ -108,6 +102,10 @@ def send_header(header, *args):
108102
hostname=self.uri.hostname,
109103
port=self.uri.port)
110104
)
105+
106+
for key, value in headers:
107+
send_header(b'%s: %s', key, value)
108+
111109
send_header(b'')
112110

113111
line = await self.a_readline()

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
setuptools.setup(
2020
name="micropython-async_websocket_client",
21-
version="0.1.7",
21+
version="0.1.8",
2222
description='Asynchronous websocket client for ESP32 controller.',
2323
long_description_content_type="text/markdown",
2424
long_description=README + '\n\n' + HISTORY,
@@ -34,5 +34,5 @@
3434
"License :: OSI Approved :: Apache Software License",
3535
"Operating System :: OS Independent",
3636
],
37-
packages=["async_websocket_client"]
37+
packages=["async_websocket_client"]
3838
)

0 commit comments

Comments
 (0)