Skip to content

Commit ea6c8c9

Browse files
committed
umqtt: support ssl
Signed-off-by: lbuque <[email protected]>
1 parent e9c62bf commit ea6c8c9

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

m5stack/libs/umqtt/__init__.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,20 @@ def __init__(
1414
ssl=False,
1515
ssl_params={},
1616
):
17-
super().__init__(client_id, server, port, user, password, keepalive, ssl, ssl_params)
17+
ssl_params1 = ssl_params
18+
if ssl:
19+
pass
20+
key_path = ssl_params1.get("key", None)
21+
key_value = self._load_file(key_path)
22+
if key_value:
23+
ssl_params1['key'] = key_value
24+
25+
cert_path = ssl_params1.get("cert", None)
26+
cert_value = self._load_file(cert_path)
27+
if cert_value:
28+
ssl_params1['cert'] = cert_value
29+
30+
super().__init__(client_id, server, port, user, password, keepalive, ssl, ssl_params1)
1831
self.set_callback(self._callback)
1932
self._topics = {}
2033

@@ -34,3 +47,14 @@ def _callback(self, topic, msg):
3447
def subscribe(self, topic, handler, qos=0):
3548
self._topics[topic] = handler
3649
return super().subscribe(topic, qos)
50+
51+
@staticmethod
52+
def _load_file(path):
53+
if type(path) is str and path.startswith("/flash"):
54+
try:
55+
with open(path, "r") as f:
56+
return f.read()
57+
except:
58+
return None
59+
else:
60+
return None

0 commit comments

Comments
 (0)