Thomas Crescenzi 2025-04-27 14:28:24 +00:00 zatwierdzone przez GitHub
commit 7719067c9f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
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

@ -36,6 +36,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)))
@ -120,6 +121,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")
@ -189,6 +191,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: