adafruit / Adafruit_Blinka_bleio

`_bleio` for Blinka based on `bleak`
58 stars 19 forks source link

"BleakError: Multiple Characteristics with this UUID" under Circuit Python 7.0 beta #37

Closed aocole closed 3 years ago

aocole commented 3 years ago

When following the BLE UART eval example, the host-computer program crashes with "bleak.exc.BleakError: Multiple Characteristics with this UUID, refer to your desired characteristic by the handle attribute instead."

$ python blea_demo.py
Trying to connect...
Connected
Traceback (most recent call last):
  File "blea_demo.py", line 22, in <module>
    uart_service = uart_connection[UARTService]
  File "/Users/aocole/.asdf/installs/python/3.8.5/lib/python3.8/site-packages/adafruit_ble/__init__.py", line 92, in __getitem__
    constructed_service = key(service=remote_service)
  File "/Users/aocole/.asdf/installs/python/3.8.5/lib/python3.8/site-packages/adafruit_ble/services/nordic.py", line 56, in __init__
    self._rx = self._server_tx
  File "/Users/aocole/.asdf/installs/python/3.8.5/lib/python3.8/site-packages/adafruit_ble/characteristics/__init__.py", line 201, in __get__
    bound_object = self.bind(service)
  File "/Users/aocole/.asdf/installs/python/3.8.5/lib/python3.8/site-packages/adafruit_ble/characteristics/stream.py", line 62, in bind
    bound_characteristic.set_cccd(notify=True)
  File "/Users/aocole/.asdf/installs/python/3.8.5/lib/python3.8/site-packages/_bleio/common.py", line 604, in set_cccd
    adapter.await_bleak(
  File "/Users/aocole/.asdf/installs/python/3.8.5/lib/python3.8/site-packages/_bleio/common.py", line 140, in await_bleak
    return future.result(timeout)
  File "/Users/aocole/.asdf/installs/python/3.8.5/lib/python3.8/concurrent/futures/_base.py", line 439, in result
    return self.__get_result()
  File "/Users/aocole/.asdf/installs/python/3.8.5/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
    raise self._exception
  File "/Users/aocole/.asdf/installs/python/3.8.5/lib/python3.8/site-packages/bleak/backends/corebluetooth/client.py", line 385, in start_notify
    characteristic = self.services.get_characteristic(char_specifier)
  File "/Users/aocole/.asdf/installs/python/3.8.5/lib/python3.8/site-packages/bleak/backends/service.py", line 179, in get_characteristic
    raise BleakError(
bleak.exc.BleakError: Multiple Characteristics with this UUID, refer to your desired characteristic by the `handle` attribute instead.

I am running:

Here's the output of the pip install to capture versions of everything:

$ pip3 install --upgrade adafruit-blinka-bleio adafruit-circuitpython-ble
Requirement already satisfied: adafruit-blinka-bleio in ./.asdf/installs/python/3.8.5/lib/python3.8/site-packages (2.2.0)
Requirement already satisfied: adafruit-circuitpython-ble in ./.asdf/installs/python/3.8.5/lib/python3.8/site-packages (8.0.2)
Requirement already satisfied: bleak==0.11.0 in ./.asdf/installs/python/3.8.5/lib/python3.8/site-packages (from adafruit-blinka-bleio) (0.11.0)
Requirement already satisfied: adafruit-blinka in ./.asdf/installs/python/3.8.5/lib/python3.8/site-packages (from adafruit-blinka-bleio) (6.13.0)
Requirement already satisfied: pyobjc-framework-CoreBluetooth in ./.asdf/installs/python/3.8.5/lib/python3.8/site-packages (from bleak==0.11.0->adafruit-blinka-bleio) (7.3)
Requirement already satisfied: pyobjc-core in ./.asdf/installs/python/3.8.5/lib/python3.8/site-packages (from bleak==0.11.0->adafruit-blinka-bleio) (7.3)
Requirement already satisfied: pyobjc-framework-libdispatch in ./.asdf/installs/python/3.8.5/lib/python3.8/site-packages (from bleak==0.11.0->adafruit-blinka-bleio) (7.3)
Requirement already satisfied: Adafruit-PlatformDetect>=3.13.0 in ./.asdf/installs/python/3.8.5/lib/python3.8/site-packages (from adafruit-blinka->adafruit-blinka-bleio) (3.15.3)
Requirement already satisfied: Adafruit-PureIO>=1.1.7 in ./.asdf/installs/python/3.8.5/lib/python3.8/site-packages (from adafruit-blinka->adafruit-blinka-bleio) (1.1.9)
Requirement already satisfied: pyftdi>=0.40.0 in ./.asdf/installs/python/3.8.5/lib/python3.8/site-packages (from adafruit-blinka->adafruit-blinka-bleio) (0.53.2)
Requirement already satisfied: pyserial>=3.0 in ./.asdf/installs/python/3.8.5/lib/python3.8/site-packages (from pyftdi>=0.40.0->adafruit-blinka->adafruit-blinka-bleio) (3.5)
Requirement already satisfied: pyusb<1.2.0,>=1.0.0 in ./.asdf/installs/python/3.8.5/lib/python3.8/site-packages (from pyftdi>=0.40.0->adafruit-blinka->adafruit-blinka-bleio) (1.1.0)
Requirement already satisfied: pyobjc-framework-Cocoa>=7.3 in ./.asdf/installs/python/3.8.5/lib/python3.8/site-packages (from pyobjc-framework-CoreBluetooth->bleak==0.11.0->adafruit-blinka-bleio) (7.3)
tannewt commented 3 years ago

This is due to CircuitPython 7.0.0 providing a UART for the CP serial link. Look like we'll need to make the libraries handle multiple services with the same UUID.

dhalbert commented 3 years ago

I wonder if it would be worth using some unique UUID's for the CP serial link. There are plenty of cases of people using non-Nordic UUIDs for serial.

tannewt commented 3 years ago

I was hoping it'd work with existing NUS clients (and it does). The CP version has a user description to distinguish it.

tannewt commented 3 years ago

I changed my mind and am switching it to a CircuitPython specific base UUID. That way we can add extra info as well but examples can work as-is by changing the base UUID.

tannewt commented 3 years ago

Absolute Newest CircuitPython should work ok again. It no longer uses the nordic UUIDs for the serial.