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

custom service discovery in BLE_Central

Hi,

I want to develop central code to discover services of 3rd party device and to discover their services and read/write characteristics.

As seen many examples from SDK below is my understanding:

1. Include db_discovery_init() 

2. call ble_db_discovery_start() on BLE_GAP_EVT_CONNECTED event in ble_evt_handler().

3. While initlaizing need to init service which is going to discover as below:

like in BLE_blinky example,includes ble_lbs service as below :


static void db_disc_handler(ble_db_discovery_evt_t * p_evt)
{
    ble_lbs_on_db_disc_evt(&m_ble_lbs_c, p_evt);
}

So my question is:

While db_discovery_init() which service should initialize in db_disc_handler() for custom service discovery? when we don't know which service is advertising by other device.

And

How to discover the services and print this and its characteristics on console. Same as we can see in nrf Connect app. Please suggest or share suitable code except BLE_UART example code.

Please help me on this asap.

Regards,

Prajakta

Parents
  • Hi Prajakta, 

    The db_disc_handler() is where you handle the events from the db discovery library, for example when the discovery is complete, or when the service is not found. 

    However, the db discovery module was not really made for generic service discovery. This means usually you need to provide the service UUID(s) you want to discover to the module before it started. 

    To be able to do generic discovery (where you discovery all UUIDs) you would need to modify it a little bit. There is some discussion here. Please have a look and let me know if you have any question. 

  • I am using BLE_Blinky application, in that after connection done, in ble_evt_handler (),handle_assign function is there, then they called ble_db_discovery_start.

    As per this discussion, need to call sd_ble_gattc_primary_services_discover.
    1.So where I can call this function with parameters?

    And

    2. Can you help me for flow for service discovery from start(init) to end in example code.I am able to do it for ble_lbs_c service(blinky application). I am not getting how to replicate it for primary service discovery.

  • Hi Prajakta, 


    What you are planing to do requires you to have good understanding on how service discovery works. Have you studied the db_discovery library ? And understand how it works ? 

    Could you describe what kind of application you are planning to make ? Maybe you don't need to discover generic services. 

    If you find you need to do that, you maybe better not use the db_discovery but better write yourself some code to do so. I would suggest you to follow this sequence chart. After you find the UUID and the handle of the service (I assume you know how the attribute table organized) you can start discovery the characteristic. After that, you can continue to do primary service discovery from the last handle you have of the last primary service discovery response. 

    Basically what you need to do will be very similar to what we have done in the db_discovery, except for that the db discovery has a list of services to look for (p_db_discovery->services[] table). As endnode mentioned in the other thread, you need to call sd_ble_gattc_read() when you receive BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP event and the service UUID is BLE_UUID_TYPE_UNKNOWN. If it's not UNKNOWN, but a 16 bit UUID, you can just continue to do characteristics discovery from the handle of the service. 

    A suggestion to understand how the service discovery works is to capture a sniffer trace  and capture a trace of nRF Connect to do a service discovery. 

  • Application is something as below:

    I want to develop central code whether it will scan for particular device(3rd party device(not nordic)) and connect to it and then discover their services and print it on console.and then read/write their characteristics.

    i am attaching screenshot of that device when it connects from nrf connect.

      

Reply Children
No Data
Related