0

io.receive_data too slow
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.

io.receive_data too slow

by laird_trimble on Mon Dec 30, 2019 8:06 pm

Hi All,

I am relatively new at using AdafruitIO and CircuitPython. In the main loop of my program I am polling a feed with

feedData = io.receive_data(control_feed['key'])

This appears to be a relatively slow and synchronous command that causes the main loop to grind almost to a halt. The problem is that I am also checking for some button presses during that loop and when I check the feed, the button presses become unresponsive.

Is there a way to run io.receive_data on a background queue to keep events in my main loop snappy?

Thanks for your help,

Laird

laird_trimble
 
Posts: 9
Joined: Fri Oct 09, 2009 4:01 pm

Re: io.receive_data too slow

by brubell on Thu Jan 02, 2020 2:53 pm

Hi Laird,

Is there a way to run io.receive_data on a background queue to keep events in my main loop snappy?


CircuitPython currently doesn't support asynchronous events, like polling the network interface in the background while running user code. It is something I'd like to see in the future, but does not have an ETA.

There is an alternative. If you have a Raspberry Pi, you could use our CircuitPython Libraries for Linux. For connecting to Adafruit IO, I suggest using Adafruit IO Python as it has a loop_background method which runs the network events in a separate thread than your while True loop.

- brent r.

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

Re: io.receive_data too slow

by brubell on Thu Jan 02, 2020 2:54 pm

Hi Laird,

Is there a way to run io.receive_data on a background queue to keep events in my main loop snappy?


CircuitPython currently doesn't support asynchronous events, like polling the network interface in the background while running user code. It is something I'd like to see in the future, but does not have an ETA.

There is an alternative. If you have a Raspberry Pi, you could use our CircuitPython Libraries for Linux. For connecting to Adafruit IO, I suggest using Adafruit IO Python as it has a loop_background method which runs the network events in a separate thread than your while True loop.

- brent r.

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

Re: io.receive_data too slow

by laird_trimble on Thu Jan 02, 2020 11:28 pm

Thanks Brent for your quick reply. I'm using a Metro M4 Airlift Lite so I'll just comment out the code and hope that I can remotely control this device sometime in the future when the libraries are updated.

Cheers,

Laird

laird_trimble
 
Posts: 9
Joined: Fri Oct 09, 2009 4:01 pm

Re: io.receive_data too slow

by brubell on Fri Jan 03, 2020 11:12 am

laird_trimble wrote:Thanks Brent for your quick reply. I'm using a Metro M4 Airlift Lite so I'll just comment out the code and hope that I can remotely control this device sometime in the future when the libraries are updated.

Cheers,

Laird


It'd be more likely that it'd be an update to the CircuitPython firmware, though I'd update MiniMQTT if it occurs .

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

Please be positive and constructive with your questions and comments.