← index #1070Issue #84
Related · high · value 0.065
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 · ISSUE

umqtt.simple check_msg() leaves socket in nonblocking state

closedby peterhinchopened 2016-07-31updated 2016-07-31

This causes failure in a subsequent call to subscribe() as reported here. The following (tested) fix is one option:

    def check_msg(self):
        self.sock.setblocking(False)
        result = self.wait_msg()
        self.sock.setblocking(True)
        return result
1 comment
pfalcon · 2016-07-31

Thanks for diagnosing. And a stupid think on m part of course, fixed as was intended in https://github.com/micropython/micropython-lib/commit/4a8ef9f99c12e6093c3dcaf22e822a035ffb18a8

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