← index #1070PR #88
Related · medium · value 1.084
QUERY · ISSUE

uMQTT_Simple suggestions: #1: Return ping result instead of None & #2: Make socket write under 'disconnect' & 'ping' non-blocking

openby magnus-0opened 2025-12-05updated 2025-12-09

Suggestion (#1) for a small change in line 205 ('section' #PINGRESP in function wait_msg):

return res[0] instead of return None

This allows you to check in your own consumer code that called check_msg() or wait_msg(), that the ping response came by and was valid, e.g.: if(oReply == 0xD0): # valid ping response


And suggestion (#2) for another small change in line 122 (section 'ping') and line 118 (section 'disconnect'):

add line self.sock.setblocking(False) in front of self.sock.write(b"...")

This prevents lóóóng (default 30 secs?) lock-ups when the connection is lost (or not ready yet).
I haven't experienced a down-side yet of this non-blocking write (with and without a working connection).

P.s. I guess the problem is only valid when using SSL, as the (plain) socket is otherwise already initiated with specified timeout at 'connect' and may not stall that long. Once wrapped in an SSL socket though, the original timeout seems either lost or ineffective. Attempting to use settimeout(t) instead of setblocking(False) here before writing to the socket, is currently not possible with SSL sockets in micropython (see this request)

Thanks!

CANDIDATE · PULL REQUEST

umqtt.simple: do not close the socket in ping()

mergedby puuuopened 2016-08-08updated 2016-08-12

IMHO there is no need to close the socket in ping() and it break the MQTT connection.

1 comment
pfalcon · 2016-08-10

Thanks, dunno how that close got in there.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied