kopia lustrzana https://github.com/micropython/micropython-lib
umqtt.simple: Restore legacy ssl/ssl_params arguments.
Commit 35d41dbb0e
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 <damien@micropython.org>
pull/936/head
rodzic
96e17b65d1
commit
98d0a2b69a
|
@ -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.
|
# Originally written by Paul Sokolovsky.
|
||||||
|
|
||||||
|
require("ssl")
|
||||||
|
|
||||||
package("umqtt")
|
package("umqtt")
|
||||||
|
|
|
@ -17,6 +17,7 @@ class MQTTClient:
|
||||||
password=None,
|
password=None,
|
||||||
keepalive=0,
|
keepalive=0,
|
||||||
ssl=None,
|
ssl=None,
|
||||||
|
ssl_params={},
|
||||||
):
|
):
|
||||||
if port == 0:
|
if port == 0:
|
||||||
port = 8883 if ssl else 1883
|
port = 8883 if ssl else 1883
|
||||||
|
@ -25,6 +26,7 @@ class MQTTClient:
|
||||||
self.server = server
|
self.server = server
|
||||||
self.port = port
|
self.port = port
|
||||||
self.ssl = ssl
|
self.ssl = ssl
|
||||||
|
self.ssl_params = ssl_params
|
||||||
self.pid = 0
|
self.pid = 0
|
||||||
self.cb = None
|
self.cb = None
|
||||||
self.user = user
|
self.user = user
|
||||||
|
@ -65,7 +67,12 @@ class MQTTClient:
|
||||||
self.sock.settimeout(timeout)
|
self.sock.settimeout(timeout)
|
||||||
addr = socket.getaddrinfo(self.server, self.port)[0][-1]
|
addr = socket.getaddrinfo(self.server, self.port)[0][-1]
|
||||||
self.sock.connect(addr)
|
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)
|
self.sock = self.ssl.wrap_socket(self.sock, server_hostname=self.server)
|
||||||
premsg = bytearray(b"\x10\0\0\0\0\0")
|
premsg = bytearray(b"\x10\0\0\0\0\0")
|
||||||
msg = bytearray(b"\x04MQTT\x04\x02\0\0")
|
msg = bytearray(b"\x04MQTT\x04\x02\0\0")
|
||||||
|
|
Ładowanie…
Reference in New Issue