Page 1 of 1

BLE characteristic_user_description (0x2901)

Posted: Sun Jan 31, 2021 3:28 pm
by Simpler1
How is a Bluetooth Low Energy user description supposed to be defined?

I've tried the following:

Code: Select all

_FILES_UUID = bluetooth.UUID("7a890001-e96d-4842-8b3d-69ce27889cd6")
_FILE_COUNT_CHAR = (
    bluetooth.UUID("7a890002-e96d-4842-8b3d-69ce27889cd6"),
    bluetooth.FLAG_NOTIFY | bluetooth.FLAG_WRITE,
    (
        (
          # org.bluetooth.descriptor.gatt.characteristic_user_description
          bluetooth.UUID(0x2901),
          bluetooth.FLAG_READ | bluetooth.FLAG_NOTIFY | bluetooth.FLAG_WRITE,
        ),
    )
)
_FILES_SERVICE = (
    _FILES_UUID,
    (_FILE_COUNT_CHAR,),
)
with

Code: Select all

class BLE_SERVER:
    def __init__(self, ble, name='my_server'):
        self._ble = ble
        ((self._file_count_handle, self._file_desc_handle),) = self._ble.gatts_register_services((_FILES_SERVICE,))
        self._ble.gatts_write(self._file_desc_handle, "My Files Description")
But the value for the description is never written.

Re: BLE characteristic_user_description (0x2901)

Posted: Mon Feb 08, 2021 7:06 am
by jimmo
Simpler1 wrote:
Sun Jan 31, 2021 3:28 pm
But the value for the description is never written.
That code looks like it should work. I see the same issue on my pyboard-d running 1.14.

I will enable NimBLE tracing and find out (and raise a bug/pr).

Looks like writing to the descriptor raises the event but doesn't seem to be stored in the gatts db.

Re: BLE characteristic_user_description (0x2901)

Posted: Tue Feb 09, 2021 12:07 am
by jimmo
Simpler1 wrote:
Sun Jan 31, 2021 3:28 pm
How is a Bluetooth Low Energy user description supposed to be defined?
Argh... NimBLE treats descriptors differently to characteristics for how it sets flags.

As a temporary workaround:

Code: Select all

_FLAG_DESC_READ = const(1)
_FLAG_DESC_WRITE = const(2)
and change the registration to

Code: Select all

        (
          # org.bluetooth.descriptor.gatt.characteristic_user_description
          bluetooth.UUID(0x2901),
          _FLAG_DESC_READ | _FLAG_DESC_WRITE,
        ),
        
and your code will start working.

I will send a PR to update modbluetooth do do this mapping for you so that your existing code will start working. Raised https://github.com/micropython/micropyt ... ues/6864in the meantime. Thanks for the report!

Re: BLE characteristic_user_description (0x2901)

Posted: Thu Feb 11, 2021 3:29 pm
by Simpler1
Thanks Jimmo. That worked.

Re: BLE characteristic_user_description (0x2901)

Posted: Sat Mar 13, 2021 9:29 pm
by mirronelli
I have spent a long evening figuring this out until I desperately found this post.
Thanks for digging into this.

For the sake of others, could this be documented for the current version, until a new version fixing this is out?

Re: BLE characteristic_user_description (0x2901)

Posted: Thu Nov 18, 2021 4:17 pm
by MerseyViking
I have, like @mirronelli, been bashing my head against a wall trying to get this to work. It really does need highlighting in the documentation.

Re: BLE characteristic_user_description (0x2901)

Posted: Wed May 25, 2022 12:34 am
by vlasoveqn
Thank you for this discussion! I, too, was having problems with descriptors being able to neither be read nor written. As of today, the differing value of descriptor RW flags has _not_ been added to the MicroPython documentation online.