Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    BLE custom service/characteristics handles and descriptors

    Scheduled Pinned Locked Moved LoPy
    blegattservicescharacteristics
    9 Posts 3 Posters 1.1k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      robertsehlstedt
      last edited by

      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?

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jcaron @robertsehlstedt
        last edited by

        @robertsehlstedt isn’t the example in https://docs.pycom.io/firmwareapi/pycom/network/bluetooth/gattscharacteristic/ exactly what you are looking for?

        R 1 Reply Last reply Reply Quote 0
        • R Offline
          robertsehlstedt @jcaron
          last edited by

          @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.

          J 1 Reply Last reply Reply Quote 0
          • R Offline
            robertsehlstedt
            last edited by

            Bumping this because it's a bit urgent!

            1 Reply Last reply Reply Quote 0
            • R Offline
              robertsehlstedt
              last edited by

              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
              
              1 Reply Last reply Reply Quote 0
              • J Offline
                jcaron @robertsehlstedt
                last edited by

                @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?

                1 Reply Last reply Reply Quote 0
                • A Offline
                  andreas
                  last edited by andreas

                  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-service

                  So, 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.

                  2213e1d7-ff69-46b1-a084-5b1b9112b646-image.png

                  Our story is that we are currently trying to bring https://github.com/hiveeyes/hiveeyes-micropython-firmware into the world field 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.

                  9b23ec42-a08b-443a-9c06-09451ed41fb4-image.png

                  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

                  J 1 Reply Last reply Reply Quote 0
                  • J Offline
                    jcaron @andreas
                    last edited by

                    @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 for xQueueReceive, apparently.

                    You would also have to add the user description as an allowed argument (line 1192) and process that like the other optional parameters.

                    A 1 Reply Last reply Reply Quote 0
                    • A Offline
                      andreas @jcaron
                      last edited by andreas

                      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 use esp_ble_gatts_add_char_descr then wait for xQueueReceive, 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-L1290

                      Thanks 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

                      1 Reply Last reply Reply Quote 0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      • 1 / 1
                      • First post
                        Last post

                      Pycom on Twitter

                      Pycom