This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

ble_db_discover for two services and one connection handle

Hello,

I'm trying to use the ble_db_discovery module to collect characteristic UUIDs and handles for two services on the same node, with the same connection handle. I first implemented a test program that registers just one service UUID, and it works fine. Then I changed the program to register the other UUID, and that also works well. Both versions discover characteristics of just one service.

The documentation for the discovery module suggests we can register more than one service.

Yet when I try registering for both services (two calls to ble_db_discovery_evt_register) no characteristics are found.

In attempting to understand what is happening, I added more log statements to ble_db_discovery.c. What I notice is that, for the first service that the module explores by enumerating handles, it does appear to go through all the handles that it should. Basically it is calling sd_ble_gattc_characteristics_discover and then processing events. However, when this is completed for the first service, instead of again calling sd_ble_gattc_characteristics_discover, there is a call to sd_ble_gattc_primary_services_discover, and I'm not sure what happens after that.

The other thing I notice is that db_disc_handler is not called with the discovery_complete event after the first service has been explored, because ble_db_discover.c queues the event triggers until all registered services are explored.

Is there an example of using ble_db_discovery for more than one registered service for a single node (one connection handle)?

- T.Herman

(This question uses SDK15.3)

  • Then I changed the program to register the other UUID, and that also works well. Both versions discover characteristics of just one service.

     So it doesn't work, since you are only seeing one service?

    I don't understand if you want to do service discovery on two services, or if you want to discover multiple characteristics in one service.

    Perhaps you can check out the ble_app_hrs_c example in SDK15.3.0\examples\ble_central\ble_app_hrs_c, as this discovers two services, BAS and HRS.

    If you want to see how to discover several characteristics in the same service, take a look at the ble_app_uart_c example, which discovers both the RX and TX characteristic. 

    I am not sure I understood your question completely, but does studying those example answer your questions?

    Since I suspect you are not sure how to discover more characteristics, check out ble_app_uart_c:

    in db_disc_handler() in main.c you set the callback for each service. In this case, only one: (but in the ble_app_hrs_c, you will see that there are two)

    ble_nus_c_on_db_disc_evt(&m_ble_nus_c, p_evt);

    this sets the callback ble_nus_c_on_db_disc_evt() ain ble_nus_c.c as a callback whenever a service with characteristics is discovered. 

    In this callback function, you can see how the function checks if:

    1. It is a BLEDB_DISCOVERY_COMPLETE event, 2 the discovered service has UUID BLE_UUID_NUS_SERVICE, and 3: if the the UUID has the correct type (maybe a bit redundant)

    If all of these are true, then it will iterate through all the characteristics in that discovery event. So this will hold the discovery of all characteristics within one service. Then it sets all the handles, based on the different characteristics. 

    Best regards,

    Edvin

  • This took forever to debug. Initially I tried to combine the discovery of the primary characteristic with general services discovery (like dis_c does) using just the db_discovery call. In theory this works. The problem was that the peripheral device is highly sensitive to the timing of operations after connection. When I instead used hard-coded values for handles, the application worked. 

Related