Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

umqtt.simple: add ping_response_received for ping handling #850

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions micropython/umqtt.simple/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions micropython/umqtt.simple/umqtt/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(
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)))
Expand Down Expand Up @@ -112,6 +113,7 @@ def disconnect(self):

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")
Expand Down Expand Up @@ -181,6 +183,7 @@ def wait_msg(self):
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:
Expand Down
Loading