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.

  • ok.
     I am facing issue here.in on_primary_srv_discovery_rsp() function. It causes many issues ahead.
    if (p_ble_gattc_evt->conn_handle != p_db_discovery->conn_handle)
    {

    NRF_LOG_INFO("p_ble_gattc_evt->conn_handle: %d, p_db_discovery->conn_handle: %d",p_ble_gattc_evt->conn_handle,p_db_discovery->conn_handle);
     return;
    }

    Code return from here.

    terminal on output as below:

    <info> ble_db_disc: p_ble_gattc_evt->conn_handle: 0, p_db_discovery->conn_handle: 65535

    Can you please help me with this?

  • Are you still combining with the db_discovery module ? For your purpose, I suggest not to use db_discovery module. 

  • Ok. Then why i am getting gattc_evt -> conn_hndle = 0.

    As you said i have added sd_ble_gattc_primary_services_discover (), and after that calling characteristics discover()  function but it fails. I think conn_hdle is same for both functions so this issue is coming. 

    Please correct me.

  • Connection handle = 0 is normal . If you have only one connection, the conn_hndle will be 0 . The BLE_CONN_HANDLE_INVALID is 0xFFFF instead. 

  • Thank you Hung bui for prompt reply.You cleared my various doubts and helped me a lot at every point. 

    Need little bit help.

    I am using characteristics_discover() function as it is in ble_db_discovery.c file from SDK.

    It gives response to on_characteristic_discovery_rsp() function.

    In that function i am failing at (p_ble_gattc_evt->gatt_status == BLE_GATT_STATUS_SUCCESS).

    Can you please check above code and please correct me, it will be very helpful.

Reply
  • Thank you Hung bui for prompt reply.You cleared my various doubts and helped me a lot at every point. 

    Need little bit help.

    I am using characteristics_discover() function as it is in ble_db_discovery.c file from SDK.

    It gives response to on_characteristic_discovery_rsp() function.

    In that function i am failing at (p_ble_gattc_evt->gatt_status == BLE_GATT_STATUS_SUCCESS).

    Can you please check above code and please correct me, it will be very helpful.

Children
Related