Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use multiprocessing on the BLE connections to retrieve data from multipe devices at the same time #8

Open
sreerajpunnoli opened this issue Mar 10, 2021 · 5 comments

Comments

@sreerajpunnoli
Copy link

I have been trying to get data out from multiple pulse-oximeters at the same time. I was able to run them separately in two different environments and able to extract data from two pulse-oximeters at the same time. I tried to use multiprocessing after the BLE connection to retrieve data parallelly from two pulse-oximeters in the same environment, the connection is getting lost and data is no longer getting received. Then I removed multiprocessing to check whether the code is right and verified that the data is getting retrieved from the code. I am using the example simple test code as a reference.

How do I retrieve data from multiple BLE devices at the same time using multiprocessing with the library?

@dhalbert
Copy link
Contributor

What are you running the library on? Is it a host computer that's running regular Python, and you're using Blinka, or are you using an nRF or Airlift board? My guess is the first thing, if you're using multiprocessing.

@sreerajpunnoli
Copy link
Author

sreerajpunnoli commented Mar 10, 2021

I have tried it on a Raspberry Pi 4 and a Mac

@dhalbert
Copy link
Contributor

The adafruit-blinka-bleio library, which you are using, uses the bleak library to do BLE on host computers. Bleak in turn uses different BLE software on each different operating system. My guess is that something either about bleak or the underlying software is getting confused about two seemingly identical devices. I'd suggest trying on Windows as well, to confirm. Then try a simple bleak-based program that tries to connect to two identical pulse oximeters and see what happens. You might also inquire with bleak about whether people have tried running multiple instances in separate processes.

It would also be interesting for you to sidestep multiprocessing right now and just try running two processes by hand in different terminal windows to connect to the two pulse oximeters to make sure the issue is not with multiprocessing or your use of it.

@sreerajpunnoli
Copy link
Author

Thanks, @dhalbert for your reply. I modified the code a little bit and ran it on mac, windows, and Raspberry Pi OS. Both Mac and Windows machines are now streaming at the same time just fine in multiprocessing. But the issue is still happening in Raspberry Pi OS. In Raspberry Pi 4 with Raspberry Pi OS, the connect method in BLERadio class is getting called and it is waiting forever and not throwing timeout exception. When I removed the multiprocessing, connect method works fine in Raspberry Pi OS. It seems like a library issue. Please suggest.

@dhalbert
Copy link
Contributor

dhalbert commented Mar 12, 2021

There is an issue with the BLE firmware for Raspberry Pi 3B+ and 4. See https://learn.adafruit.com/circuitpython-ble-libraries-on-any-computer/install-ble-libraries#raspberry-pi-3b-plus-and-4b-firmware-fix-3074928-6. The firmware is now at version rpt7, I think, but I am not sure this issue has been fixed. Try the rp2 version. I have found it necessary to power-cycle the board after updating the firmware, at least some of the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants