Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

umqtt.simple: Restore legacy ssl/ssl_params arguments. #936

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion micropython/umqtt.simple/manifest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
metadata(description="Lightweight MQTT client for MicroPython.", version="1.5.0")
metadata(description="Lightweight MQTT client for MicroPython.", version="1.6.0")

# Originally written by Paul Sokolovsky.

require("ssl")

package("umqtt")
9 changes: 8 additions & 1 deletion micropython/umqtt.simple/umqtt/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(
password=None,
keepalive=0,
ssl=None,
ssl_params={},
):
if port == 0:
port = 8883 if ssl else 1883
Expand All @@ -25,6 +26,7 @@ def __init__(
self.server = server
self.port = port
self.ssl = ssl
self.ssl_params = ssl_params
self.pid = 0
self.cb = None
self.user = user
Expand Down Expand Up @@ -65,7 +67,12 @@ def connect(self, clean_session=True, timeout=None):
self.sock.settimeout(timeout)
addr = socket.getaddrinfo(self.server, self.port)[0][-1]
self.sock.connect(addr)
if self.ssl:
if self.ssl is True:
# Legacy support for ssl=True and ssl_params arguments.
import ssl

self.sock = ssl.wrap_socket(self.sock, **self.ssl_params)
elif self.ssl:
self.sock = self.ssl.wrap_socket(self.sock, server_hostname=self.server)
premsg = bytearray(b"\x10\0\0\0\0\0")
msg = bytearray(b"\x04MQTT\x04\x02\0\0")
Expand Down
Loading