hbldh / bleak

A cross platform Bluetooth Low Energy Client for Python using asyncio
MIT License
1.82k stars 300 forks source link

BLE problems on Raspberry Pi 3B+ and 4 #332

Closed dhalbert closed 3 years ago

dhalbert commented 4 years ago

This is not a bleak problem per se, I believe.

I'm trying to get bleak to work on an RPi 4 (and 3B+). It works fine on an RPi Zero W and 3B, but swapping the SD card from the RPi Zero W into an RPi 4 or 3B+ (assuring that the OS setup is identical) gives this error when trying to do service discovery:

...
  File "/home/pi/.local/lib/python3.7/site-packages/bleak/backends/bluezdbus/client.py", line 154, in connect
    await self.get_services()
  File "/home/pi/.local/lib/python3.7/site-packages/bleak/backends/bluezdbus/client.py", line 384, in get_services
    raise BleakError("Services discovery error")

The properties value ServicesResolved never becomes True, which causes the error.

If anyone has gotten bleak to work on an RPi4, I'd love to hear what you had to do. I've scoured the RPi forums, etc., and haven't come up with any solution. The wifi/BLE adapter chip is supposed to be identical between the two boards. [EDIT: In fact, the wifi hardware changed between 3B and 3B+, though it's hard to find this out.] Thanks.

EDIT: Further testing shows it works on Pi0W and Pi3B, but not on Pi3B+ and Pi4B.

dhalbert commented 4 years ago

This appears to be a bluez-firmware problem which manifests on more recent RPi's. Discussion here: https://github.com/adafruit/Adafruit_CircuitPython_BLE_BerryMed_Pulse_Oximeter/issues/3#issuecomment-708007815

This appears to be a bluez-firmware problem. As of this writing, the latest version is bluez-firmware-1.2-4+rpt5. I had to roll back to bluez-firmware-1.2-4+rpt2 to get this to work. I downloaded the .deb from http://archive.raspberrypi.org/debian/pool/main/b/bluez-firmware/bluez-firmware_1.2-4+rpt2_all.deb. Versions rpt3 and rpt4 didn't work. What seems like the same problem was reported here: https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=285641&p=1728626, and that report rolled back to rpt2 also.

EDIT: bluez-firmware issue being tracked here: https://github.com/RPi-Distro/bluez-firmware/issues/6

hbldh commented 4 years ago

This is a highly interesting find; thank you for documenting it! I will add a link to this issue on the new troubleshooting page in the docs (#330).

dhalbert commented 3 years ago

Reopening this for your interest because there is new firmware under test at https://github.com/RPi-Distro/bluez-firmware/issues/6. Unfortunately it does not work for me.

dhalbert commented 3 years ago

Reopening this for your interest because there is new firmware under test at RPi-Distro/bluez-firmware#6. Unfortunately it does not work for me.

Turns out for some reason I had to power cycle the board (not just reboot) in order to test the new firmware properly. It now does work for me, getting values from a pulse oximeter via our software on top of bleak.

dhalbert commented 3 years ago

The bluez-firmware-1.2-4+rpt7 and rpt8 versions fix the problem mentioned. Use rpt8, which includes security fix not in rpt7.