Home/Support/Support Forum/How to use urequests to post nonblocking data?
New and improved user forum site going live on 12/6 (All users will need to reset their password when the new forum is active)
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

How to use urequests to post nonblocking data?

0 votes
I'm using urequests.py micropython library to post traffic on Xbee Cellular LTE Cat1 module. I find that urequests.py is blocking, but would like to make it nonblocking. Digging into the library, I found that the socket can be made nonblocking by using the following command 's.setblocking(False)'. I then registered a polling object and then began polling the object using poll.poll(polling_ojbect). In urequests.py, the very first socket command after creating the socket is 's.connect()'. I found that the response back from 's.connect()' in nonblocking mode takes much longer than in blocking mode (~2 minutes vs ~2 seconds). This leads me to believe I'm doing something wrong. Is this the conventional method of nonblocking communication using micropython or is there a better way? Also, why the big difference in response times?
asked Aug 10 in Python by vu2712 New to the Community (0 points)

Please log in or register to answer this question.

1 Answer

0 votes
I don't know if you are doing this or not but try putting the s.connect in a while loop.
answered Aug 11 by mvut Veteran of the Digi Community (15,515 points)
Thanks mvut for your response. I did put it in a loop.  I'm thinking that I will put put a timeout on the s.connect(), leave the socket open while I transmit, so that I don't get hit by the connect time.  Then enable the polling on just the response.
...