micropython / micropython/micropython-lib

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

Open
#1,070 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.9k
Forks
1.1k
Avg merge
7d 6h
Merged PRs (30d)
3

Description

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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the uMQTT_Simple implementation at wait_msg section #PINGRESP around line 205, then inspect ping and disconnect around lines 122 and 118. Check how check_msg(), wait_msg(), and SSL sockets currently handle writes. Done means returning the ping response value and preventing the specified socket writes from blocking, with behavior verified for connected and lost connections.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.