Skip to content

Commit 8322f75

Browse files
committed
umqtt.simple: add ping_response_received for ping handling.
1 parent 45ead11 commit 8322f75

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

Diff for: micropython/umqtt.simple/README.rst

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

Diff for: micropython/umqtt.simple/umqtt/simple.py

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def __init__(
3434
self.lw_msg = None
3535
self.lw_qos = 0
3636
self.lw_retain = False
37+
self.ping_response_received = False
3738

3839
def _send_str(self, s):
3940
self.sock.write(struct.pack("!H", len(s)))
@@ -112,6 +113,7 @@ def disconnect(self):
112113

113114
def ping(self):
114115
self.sock.write(b"\xc0\0")
116+
self.ping_response_received = False
115117

116118
def publish(self, topic, msg, retain=False, qos=0):
117119
pkt = bytearray(b"\x30\0\0\0")
@@ -181,6 +183,7 @@ def wait_msg(self):
181183
if res == b"\xd0": # PINGRESP
182184
sz = self.sock.read(1)[0]
183185
assert sz == 0
186+
self.ping_response_received = True
184187
return None
185188
op = res[0]
186189
if op & 0xF0 != 0x30:

0 commit comments

Comments
 (0)