BLE characteristic_user_description (0x2901)

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Simpler1
Posts: 16
Joined: Wed Jan 06, 2021 6:30 pm

BLE characteristic_user_description (0x2901)

Post by Simpler1 » Sun Jan 31, 2021 3:28 pm

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.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: BLE characteristic_user_description (0x2901)

Post by jimmo » Mon Feb 08, 2021 7:06 am

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.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: BLE characteristic_user_description (0x2901)

Post by jimmo » Tue Feb 09, 2021 12:07 am

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!

Simpler1
Posts: 16
Joined: Wed Jan 06, 2021 6:30 pm

Re: BLE characteristic_user_description (0x2901)

Post by Simpler1 » Thu Feb 11, 2021 3:29 pm

Thanks Jimmo. That worked.

mirronelli
Posts: 1
Joined: Sat Mar 13, 2021 9:25 pm

Re: BLE characteristic_user_description (0x2901)

Post by mirronelli » Sat Mar 13, 2021 9:29 pm

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?

MerseyViking
Posts: 5
Joined: Tue Nov 16, 2021 10:14 pm

Re: BLE characteristic_user_description (0x2901)

Post by MerseyViking » Thu Nov 18, 2021 4:17 pm

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.

vlasoveqn
Posts: 11
Joined: Wed Apr 21, 2021 7:12 pm

Re: BLE characteristic_user_description (0x2901)

Post by vlasoveqn » Wed May 25, 2022 12:34 am

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.

Post Reply