๐ŸŽ„โ›„โ„๏ธ๐ŸŽ It's beginning to look a lot like ADABOX-mas! The next ADABOX from Adafruit ships soon! Get yours now, or give as a gift! ๐ŸŽ„โ›„โ„๏ธ๐ŸŽ
0

Timeout on Python send_data() and recieve()
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Timeout on Python send_data() and recieve()

by amac09 on Tue Oct 22, 2019 2:38 pm

I have a about 10 send_data() calls and 4 receive() calls running my programs main loop using the Python API. These are called once every 30 seconds. Fairly frequently the main loop will pause waiting for these calls to clear. Is there a way to set a timeout on the calls, or make them non-blocking in the Python API?

amac09
 
Posts: 1
Joined: Tue Oct 22, 2019 2:18 pm

Re: Timeout on Python send_data() and recieve()

by brubell on Tue Oct 22, 2019 3:14 pm

Hi amac09,

amac09 wrote:I have a about 10 send_data() calls and 4 receive() calls running my programs main loop using the Python API. These are called once every 30 seconds. Fairly frequently the main loop will pause waiting for these calls to clear. Is there a way to set a timeout on the calls, or make them non-blocking in the Python API?


If you're using Adafruit IO Python, try switching from the HTTP API (import Client) to the MQTT API (import MQTTClient). Here's an example of its usage: https://github.com/adafruit/Adafruit_IO ... t_class.py.

You will need to rework some of your code to conform to the MQTTClient API but it's fairly straight-forwards, let me know if you have any questions or need help :-)

The MQTT API allows you to either manually pump the message loop by yourself (https://github.com/adafruit/Adafruit_IO ... ass.py#L80) or you can use loop_background which allows Adafruit IO Python to run a thread handling the message loop in the background so you can perform other actions while it's working.

- brent r.

brubell
 
Posts: 609
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.