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.
pull/890/head
Prabhu Ullagaddi 2024-11-06 17:58:20 +05:30 zatwierdzone przez Damien George
rodzic 68e3e07bc7
commit d6faaf8472
2 zmienionych plików z 3 dodań i 2 usunięć

Wyświetl plik

@ -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.

Wyświetl plik

@ -60,8 +60,9 @@ class MQTTClient:
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: