umqtt.simple: Add ping_response_received for ping handling.

Signed-off-by: Thomas Crescenzi <trescenzi@gmail.com>
pull/850/head
Thomas Crescenzi 2024-04-23 19:08:14 -04:00
rodzic 45ead11f96
commit e6bc44668d
2 zmienionych plików z 4 dodań i 0 usunięć

Wyświetl plik

@ -51,6 +51,7 @@ follows MQTT control operations, and maps them to class methods:
clean_session=True argument is used (default)).
* ``disconnect()`` - Disconnect from a server, release resources.
* ``ping()`` - Ping server (response is processed automatically by wait_msg()).
* ``ping_response_received`` - True once ping has been responded to, False if not. Set by wait_msg() and reset upon next ping().
* ``publish()`` - Publish a message.
* ``subscribe()`` - Subscribe to a topic.
* ``set_callback()`` - Set callback for received subscription messages.

Wyświetl plik

@ -34,6 +34,7 @@ class MQTTClient:
self.lw_msg = None
self.lw_qos = 0
self.lw_retain = False
self.ping_response_received = False
def _send_str(self, s):
self.sock.write(struct.pack("!H", len(s)))
@ -112,6 +113,7 @@ class MQTTClient:
def ping(self):
self.sock.write(b"\xc0\0")
self.ping_response_received = False
def publish(self, topic, msg, retain=False, qos=0):
pkt = bytearray(b"\x30\0\0\0")
@ -181,6 +183,7 @@ class MQTTClient:
if res == b"\xd0": # PINGRESP
sz = self.sock.read(1)[0]
assert sz == 0
self.ping_response_received = True
return None
op = res[0]
if op & 0xF0 != 0x30: