BLE custom service/characteristics handles and descriptors
-
Hello!
I am trying to set up BLE on my LoPy4. From my understanding, it should be possible to set up custom services and characteristics using 128-bit UUIDs. But the documentation doesn't give me any hints (as far as I can see) about how to actually set handles for a custom service or characteristic, or descriptors for that matter.Is this possible? And how?
-
Dear @jcaron,
Bringing 0x2901 CUD support to the Pycom BLE stack
You would need to modify the code you pointed out in [3] to add another descriptor for the description (it currently adds a 0x2902 CCC and you want to also add a 0x2901 CUD).
For each descriptor, you need to useesp_ble_gatts_add_char_descr
then wait forxQueueReceive
, apparently.
You would also have to add the user description as an allowed argument (line 1192) and process that like the other optional parameters.
[3] https://github.com/pycom/pycom-micropython-sigfox/blob/4d3322a60501cac1a06558a0c5c816e198570888/esp32/mods/modbt.c#L1276-L1290Thanks for outlining the procedure in detail how to go forward on this. While I might feel like I could eventually accept this challenge while receiving further guidelines from folks more fluent with C++ as well as FreeRTOS, the ESP-IDF and the Bluetooth Softwarestack incorporated into the Firmware, we are currently a bit swamped between different other things.
Saying this, we are humbly asking members from the Pycom core team here if adding this feature could be worth the effort? We can assure you we will kindly be the first betatesters of added functionality in this regard.
Maybe @semireg (@caylanlarson) and @husigeza who worked together [1] on the important improvement re. processing the
Bluetooth.CHAR_SUBSCRIBE_EVENT
might add their thoughts here?Thanks already and with kind regards,
Andreas.[1] https://github.com/pycom/pycom-micropython-sigfox/pull/121
-
@andreas This is such clearer, thanks for the detailed writeup.
There's apparently no support for this in the Pycom BLE code yet, so you would need to modify the code you pointed out in [3] to add another descriptor for the description (it currently adds a 2902 CCC and you want to also add a 2901 CUD).
For each descriptor, you need to use
esp_ble_gatts_add_char_descr
then wait forxQueueReceive
, apparently.You would also have to add the user description as an allowed argument (line 1192) and process that like the other optional parameters.
-
Hi there,
Preamble
First things first: Cheers and kudos to the whole Pycom team and community. Thanks for bringing the fine Pycom devices to us and thanks to all people who are supporting this journey. Special thanks go to @robert-hh, we have been able to build significantly on his work on finding appropriate ways to get around any quirks.
BLE GATTS Characteristic User Description (uuid=0x2901) descriptor
So, we are experiencing the same thing here as @robertsehlstedt outlined already. One remark on StackOverflow regarding how to do it in C++ resonates very much with where we are aiming at:
I am trying to add some Characteristic User Descriptions to my custom BLE GATT Service, using the mbed API. My work has so far been based on this code structure. However, I would like to add names to these characteristics. There isn't much info I could find on how to do this.
-- https://stackoverflow.com/questions/33328272/adding-characteristic-user-description-to-custom-c-ble-gatt-serviceSo, we would like to add a Characteristic User Description element (uuid=0x2901) [0] like seen within [1] in order to assign humanized names/descriptions to individual characteristics. We also found C++ code which might do similar things from Adafruit [2] and also recognized that around [3] might be the right place to add respective things for Pycom. [4] lists all available GATT descriptors as a reference.
As a picture says a thousand words, we added this from [10] to outline that we are targeting the most leaf-node elements of the BLE GATTS hierarchy - the descriptor elements - here. [11,12,13] might also give further guidance.
Our story is that we are currently trying to bring https://github.com/hiveeyes/hiveeyes-micropython-firmware into the
worldfield and look forward to unlock as many ways of doing telemetry handles as possible.So, we are humbly asking if you could take a look at this as it is currently a blocker for us when trying to unlock BLE GATT services on FiPy devices.
When everything falls into place, people will be happy to see custom Characteristic User Description (0x2901) descriptors like outlined in this screenshot from nRF Connect or their favorite choice of BLE software.
Thanks already for your efforts.
With kind regards,
Andreas.[0] https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Descriptors/org.bluetooth.descriptor.gatt.characteristic_user_description.xml
[1] https://github.com/moovel/gatt-server/blob/master/README.md#reference-output.
[2] https://github.com/adafruit/Adafruit_nRF52_Arduino/blob/68400a76662af268829e3c6c66ae62ac02eaae76/libraries/Bluefruit52Lib/src/BLECharacteristic.cpp#L316-L344
[3] https://github.com/pycom/pycom-micropython-sigfox/blob/4d3322a60501cac1a06558a0c5c816e198570888/esp32/mods/modbt.c#L1276-L1290
[4] https://www.bluetooth.com/specifications/gatt/descriptors/[10] https://www.polidea.com/blog/bluetooth-low-energy-sniffing-guide-part-2
[11] https://devzone.nordicsemi.com/f/nordic-q-a/6700/adding-characteristic-user-description-0x2901-0x2902
[12] http://developer.nordicsemi.com/nRF51_SDK/nRF51_SDK_v8.x.x/doc/8.0.0/s110/html/a00283.html
[13] https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/ble-characteristics-a-beginners-tutorial
-
@robertsehlstedt I’m not sure I really understand your issue. What is it you are actually trying to a achieve? The example shows how to define those services and characteristics, how to assign a callback to handle associated events, how to define whether they are read and/or write, etc.
Can you clarify what exactly you want to do which isn’t in that example?
-
I think I just found something! But I don't know if it's going to help me, yet.
Apparently characteristics have a method called config(). It sounds promising, and I found it by doing>>> help(characteristic)
However, I can find no documentation about arguments or what it does at all. All I find was this from the source code:
STATIC mp_obj_t bt_characteristic_config(mp_obj_t self_in) { bt_gatts_char_obj_t *self = self_in; return mp_obj_new_int(self->config); }
And when I just try to run the config without arguments, I get this.
>>> characteristic.config() 0
-
Bumping this because it's a bit urgent!
-
@jcaron I don't think so. I know how to set up a custom service and characteristic, but not how to actually modify it in any kind of way. For example what handle it should have, or what values a particular characteristic can accept.
-
@robertsehlstedt isn’t the example in https://docs.pycom.io/firmwareapi/pycom/network/bluetooth/gattscharacteristic/ exactly what you are looking for?