IanHarvey / bluepy

Python interface to Bluetooth LE on Linux
Other
1.58k stars 490 forks source link

Read characteristic value fails #453

Closed d-f-clark closed 3 years ago

d-f-clark commented 3 years ago

I have a Python app running as a BLE Peripheral on a Raspberry Pi Zero, advertising with a specific manufacturer ID. I have another Python app running as a BLE Central on a Raspberry Pi 3 Model B. The Central scans for advertising devices for 10 seconds, then loops through the list of devices (very similar to the bluepy sample app). It finds the manufacturer ID that it seeks, and connects to that device using "p = Peripheral(dev)". It then loops through the device reporting the UUID for each Service, and for each Service it loops through the set of Characteristics and reports each UUID. When it finds a specific Characteristic UUID it checks the supportsRead() method on that Characteristic object ("theChar.supportsRead()") and if that returns True it attempts to read the value from that Characteristic using "theChar.read()". This causes a series of stack messages followed by an immediate disconnect: Traceback (most recent call last): File "AppCentralMain.py", line 86, in main() File "AppCentralMain.py", line 69, in main measChar.read() File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 197, in read return self.peripheral.readCharacteristic(self.valHandle)

File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 530, in readCharacteristic resp = self._getResp('rd')

File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 407, in _getResp resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)

File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 362, in _waitResp raise BTLEDisconnectError("Device disconnected", resp)

bluepy.btle.BTLEDisconnectError: Device disconnected

On the Raspberry Pi 3 Model B: bluepy version is 1.3.0 Bluez version is 5.50-1.2~deb10u1+rpt2 armhf Raspbian version is 5.10.17-v7+ #1421 SMP Thu May 27 13:59:01 BST 2021 armv7l GNU/Linux

On the Raspberry Pi Zero: bluepy version is 1.3.0 Bluez version is 5.50-1.2~deb10u1+rpt2 armhf Raspbian version is 5.10.17+ #1421 Thu May 27 13:58:02 BST 2021 armv6l GNU/Linux

d-f-clark commented 3 years ago

Found the reason, turned off encrypted-read in the Peripheral. That said, it would be helpful if the Exception could be informative of the underlying issue encountered that caused the exception to be thrown.