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.

  • Can you share me your output on terminal?

    Calling on_primary_srv_discovery_rsp(p_db_discovery, &(p_ble_evt->evt.gattc_evt)) function under case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP is it correct?

  • Thank you so much Hung Bui....

    It also works for me.
    but now the issue is in on_primary_srv_discovery_rsp.

    if (p_ble_gattc_evt->conn_handle != p_db_discovery->conn_handle)
    {
    NRF_LOG_INFO("Return from on_primary_srv_discovery_rsp");
    return;
    }

    is something i am doing wrong?

  • i am able to discover service. but at time only 1 service is discovered.

    I think this is because as you said in previous conversation.
    Then you can continue to call sd_ble_gattc_primary_services_discover() with the last handle until you receive ATTRIBUTE_NOT_FOUND in the next correspondent event .

    But how to do it. Can you help me to add this in code. Please

  • Good to see you get some progress. 

    Please make sure you check the .count in the return argument , there can be more than one service discovered. 

    Then you should check the last service discovered and find the handle_range, find the end_handle of that range. From that you can discovery the next service by calling sd_ble_gattc_primary_services_discover with the start_handle equal end_handle + 1. 

    And continue doing so until you receive ATTRIBUTE_NOT_FOUND

  • <Please make sure you check the .count in the return argument , there can be more than one service discovered. >

    where to check in code?

    I have checked it here p_db_discovery->srv_count; it gives count = 0.

Reply Children
Related