Skip to content

uMQTT_Simple suggestions: #1: Return ping result instead of None & #2: Add make ping write non-blocking #1070

@magnus-0

Description

@magnus-0

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'):

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

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 the write in the ping function, is currently not possible with SSL sockets in micropython (see this request)

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions