From d6faaf847243766c1bca92d8bca603025d3f19ba Mon Sep 17 00:00:00 2001 From: Prabhu Ullagaddi Date: Wed, 6 Nov 2024 17:58:20 +0530 Subject: [PATCH] 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. --- micropython/umqtt.simple/manifest.py | 2 +- micropython/umqtt.simple/umqtt/simple.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/micropython/umqtt.simple/manifest.py b/micropython/umqtt.simple/manifest.py index b418995c5..45f9edfbd 100644 --- a/micropython/umqtt.simple/manifest.py +++ b/micropython/umqtt.simple/manifest.py @@ -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. diff --git a/micropython/umqtt.simple/umqtt/simple.py b/micropython/umqtt.simple/umqtt/simple.py index 6da38e445..2a5b91655 100644 --- a/micropython/umqtt.simple/umqtt/simple.py +++ b/micropython/umqtt.simple/umqtt/simple.py @@ -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: