Skip to content

Commit d966d76

Browse files
mrkeuzdpgeorge
authored andcommitted
umqtt.simple: Add example for mqtt tls.
Signed-off-by: Damien George <damien@micropython.org>
1 parent 40d707d commit d966d76

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from umqtt.simple import MQTTClient
2+
3+
# Test reception e.g. with:
4+
# mosquitto_sub -t foo_topic
5+
6+
7+
def main(server="localhost"):
8+
# NOTE: Checking server certificate is DISABLE
9+
ssl_params = {"server_hostname": server}
10+
c = MQTTClient(
11+
"umqtt_client",
12+
server=server,
13+
port=8883,
14+
user="<username>",
15+
password="<password>",
16+
keepalive=60,
17+
ssl=True,
18+
ssl_params=ssl_params,
19+
)
20+
c.connect()
21+
c.publish(b"foo_topic", b"hello")
22+
c.disconnect()
23+
24+
25+
if __name__ == "__main__":
26+
main()

0 commit comments

Comments
 (0)