@@ -702,7 +702,7 @@ def disconnect(self) -> None:
702
702
def ping (self ) -> list [int ]:
703
703
"""Pings the MQTT Broker to confirm if the broker is alive or if
704
704
there is an active network connection.
705
- Returns response codes of any messages received while waiting for PINGRESP.
705
+ Returns packet types of any messages received while waiting for PINGRESP.
706
706
"""
707
707
self ._connected ()
708
708
self .logger .debug ("Sending PINGREQ" )
@@ -1017,7 +1017,7 @@ def reconnect(self, resub_topics: bool = True) -> int:
1017
1017
def loop (self , timeout : float = 0 ) -> Optional [list [int ]]:
1018
1018
# pylint: disable = too-many-return-statements
1019
1019
"""Non-blocking message loop. Use this method to check for incoming messages.
1020
- Returns list of response codes of any messages received or None.
1020
+ Returns list of packet types of any messages received or None.
1021
1021
1022
1022
:param float timeout: return after this timeout, in seconds.
1023
1023
@@ -1073,16 +1073,17 @@ def _wait_for_msg(self) -> Optional[int]:
1073
1073
if res in [None , b"" , b"\x00 " ]:
1074
1074
# If we get here, it means that there is nothing to be received
1075
1075
return None
1076
- if res [0 ] & MQTT_PKT_TYPE_MASK == MQTT_PINGRESP :
1076
+ pkt_type = res [0 ] & MQTT_PKT_TYPE_MASK
1077
+ self .logger .debug (f"Got message type: { hex (pkt_type )} pkt: { hex (res [0 ])} " )
1078
+ if pkt_type == MQTT_PINGRESP :
1077
1079
self .logger .debug ("Got PINGRESP" )
1078
1080
sz = self ._sock_exact_recv (1 )[0 ]
1079
1081
if sz != 0x00 :
1080
1082
raise MMQTTException (f"Unexpected PINGRESP returned from broker: { sz } ." )
1081
- return MQTT_PINGRESP
1083
+ return pkt_type
1082
1084
1083
- if res [0 ] & MQTT_PKT_TYPE_MASK != MQTT_PUBLISH :
1084
- self .logger .debug (f"Got message type: { hex (res [0 ])} " )
1085
- return res [0 ]
1085
+ if pkt_type != MQTT_PUBLISH :
1086
+ return pkt_type
1086
1087
1087
1088
# Handle only the PUBLISH packet type from now on.
1088
1089
sz = self ._recv_len ()
@@ -1116,7 +1117,7 @@ def _wait_for_msg(self) -> Optional[int]:
1116
1117
elif res [0 ] & 6 == 4 :
1117
1118
assert 0
1118
1119
1119
- return res [ 0 ]
1120
+ return pkt_type
1120
1121
1121
1122
def _recv_len (self ) -> int :
1122
1123
"""Unpack MQTT message length."""
0 commit comments