Skip to content

Commit

Permalink
umqtt.simple: Add optional socket timeout to connect method.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
prabhu-yu authored and dpgeorge committed Nov 7, 2024
1 parent 68e3e07 commit d6faaf8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion micropython/umqtt.simple/manifest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
metadata(description="Lightweight MQTT client for MicroPython.", version="1.4.0")
metadata(description="Lightweight MQTT client for MicroPython.", version="1.5.0")

# Originally written by Paul Sokolovsky.

Expand Down
3 changes: 2 additions & 1 deletion micropython/umqtt.simple/umqtt/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ def set_last_will(self, topic, msg, retain=False, qos=0):
self.lw_qos = qos
self.lw_retain = retain

def connect(self, clean_session=True):
def connect(self, clean_session=True, timeout=None):
self.sock = socket.socket()
self.sock.settimeout(timeout)
addr = socket.getaddrinfo(self.server, self.port)[0][-1]
self.sock.connect(addr)
if self.ssl:
Expand Down

0 comments on commit d6faaf8

Please sign in to comment.