kopia lustrzana https://github.com/micropython/micropython-lib
umqtt.simple: Add ping_response_received for ping handling.
Signed-off-by: Thomas Crescenzi <trescenzi@gmail.com>pull/850/head
rodzic
45ead11f96
commit
e6bc44668d
|
@ -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.
|
||||
|
|
|
@ -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:
|
||||
|
|
Ładowanie…
Reference in New Issue