Skip to content

Commit 0bace17

Browse files
committed
umqtt.simple: Restore legacy ssl/ssl_params arguments.
Commit 35d41db changed the API for using SSL with umqtt, but only did a minor version increase. This broke various uses of this library, eg https://github.com/aws-samples/aws-iot-core-getting-started-micropython Reinstate the original API for specifying an SSL connection. This library now supports the following: - default, ssl=None or ssl=False: no SSL - ssl=True and optional ssl_params specified: use ssl.wrap_socket - ssl=<SSLContext instance>: use provided SSL context to wrap socket Signed-off-by: Damien George <[email protected]>
1 parent d6faaf8 commit 0bace17

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Diff for: micropython/umqtt.simple/manifest.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
metadata(description="Lightweight MQTT client for MicroPython.", version="1.5.0")
1+
metadata(description="Lightweight MQTT client for MicroPython.", version="1.6.0")
22

33
# Originally written by Paul Sokolovsky.
44

5+
require("ssl")
6+
57
package("umqtt")

Diff for: micropython/umqtt.simple/umqtt/simple.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def __init__(
1717
password=None,
1818
keepalive=0,
1919
ssl=None,
20+
ssl_params={},
2021
):
2122
if port == 0:
2223
port = 8883 if ssl else 1883
@@ -25,6 +26,7 @@ def __init__(
2526
self.server = server
2627
self.port = port
2728
self.ssl = ssl
29+
self.ssl_params = ssl_params
2830
self.pid = 0
2931
self.cb = None
3032
self.user = user
@@ -65,7 +67,12 @@ def connect(self, clean_session=True, timeout=None):
6567
self.sock.settimeout(timeout)
6668
addr = socket.getaddrinfo(self.server, self.port)[0][-1]
6769
self.sock.connect(addr)
68-
if self.ssl:
70+
if self.ssl is True:
71+
# Legacy support for ssl=True and ssl_params arguments.
72+
import ssl
73+
74+
self.sock = ssl.wrap_socket(self.sock, **self.ssl_params)
75+
elif self.ssl:
6976
self.sock = self.ssl.wrap_socket(self.sock, server_hostname=self.server)
7077
premsg = bytearray(b"\x10\0\0\0\0\0")
7178
msg = bytearray(b"\x04MQTT\x04\x02\0\0")

0 commit comments

Comments
 (0)