Skip to content

Commit d6faaf8

Browse files
prabhu-yudpgeorge
authored andcommitted
umqtt.simple: Add optional socket timeout to connect method.
If there are any network issues, mqtt will block on the socket non-deterministically. This commit introduces a `timeout` option which can be used to set a finite timeout on the socket. Upon any issue, mqtth lib will throw exception.
1 parent 68e3e07 commit d6faaf8

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

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

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

33
# Originally written by Paul Sokolovsky.
44

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ def set_last_will(self, topic, msg, retain=False, qos=0):
6060
self.lw_qos = qos
6161
self.lw_retain = retain
6262

63-
def connect(self, clean_session=True):
63+
def connect(self, clean_session=True, timeout=None):
6464
self.sock = socket.socket()
65+
self.sock.settimeout(timeout)
6566
addr = socket.getaddrinfo(self.server, self.port)[0][-1]
6667
self.sock.connect(addr)
6768
if self.ssl:

0 commit comments

Comments
 (0)