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

SDK15.0 BLE host client

Hi,Sir:

 

I am making a DEMO based on SDK15.0(SDK15.0\examples\ble_central\ble_app_hrs_c) and pca10056 for my one of important customs.I need to implement some extra software features as flowing:

  • implement BLE host client that can find a peripheral all services include SIG service and private service(this function seems as PC /Android’s nRF connect) .
  • The BLE host client can find corresponding characteristics and  of the peripheral service.

 

For BLE SIG services, I can register them in advance one by one through uint32_t ble_db_discovery_evt_register(ble_uuid_t const * p_uuid) function,then discover    services and corresponding characteristics of the services;but for private service,the user cannot know the UUID of the private service of the BLE peripheral in advance, and does not know how many private services are provided outside the BLE peripheral.

So, for the BLE host client find BLE peripheral several private services that cannot be known in advance, do you have any situation?

 

I tried to modify some code to find BLE private service:

from(SDK\nRF5_SDK_15.0.0_a53641a\examples\ble_central\ble_app_hrs_c\pca10056)as flowing:

replace

//    err_code = sd_ble_gattc_primary_services_discover(conn_handle,

//                                                      SRV_DISC_START_HANDLE,

//                                                      &(p_srv_being_discovered->srv_uuid));

with

    err_code = sd_ble_gattc_primary_services_discover(conn_handle,

    SRV_DISC_START_HANDLE,

NULL);

 

But I only get two services ,their 0x 1800和 0x1801 on on_primary_srv_discovery_rsp().

 

Attachment program and print information:

 

        p_prim_srvc_disc_rsp_evt = &(p_ble_gattc_evt->params.prim_srvc_disc_rsp);

 

        p_srv_being_discovered->srv_uuid     = p_prim_srvc_disc_rsp_evt->services[0].uuid;

        p_srv_being_discovered->handle_range = p_prim_srvc_disc_rsp_evt->services[0].handle_range;

 

        NRF_LOG_DEBUG("Current service count = %d.", p_prim_srvc_disc_rsp_evt->count);

        for(uint8_t i= 0;i< p_prim_srvc_disc_rsp_evt->count;i++)

        {

          NRF_LOG_DEBUG("Found a %d type service UUID 0x%04X", p_prim_srvc_disc_rsp_evt->services[i].uuid.type,

                                                             p_prim_srvc_disc_rsp_evt->services[i].uuid.uuid);                                                                     

          

          NRF_LOG_DEBUG("The service handle range:0x%04X--0x%04X", p_prim_srvc_disc_rsp_evt->services[i].handle_range.start_handle,

                                                                   p_prim_srvc_disc_rsp_evt->services[i].handle_range.end_handle);        

        }

 

 

<debug> ble_db_disc: Starting discovery of service with UUID 0x0 on connection handle 0x0.

<debug> ble_db_disc: Current service count = 2.

<debug> ble_db_disc: Found a 1 type service UUID 0x1800

<debug> ble_db_disc: The service handle range:0x0001--0x0009

<debug> ble_db_disc: Found a 1 type service UUID 0x1801

<debug> ble_db_disc: The service handle range:0x000A--0x000A

  • Hi,

    For most applications the 128 bit UUID is known, so you would simply add it to your list of known vendor specific UUID's. The returned uuid.type will match one of your entries in the UUID table in this case. In case the 128 bit UUID is unknown, BLE_UUID_TYPE_UNKNOWN, you can use sd_ble_gattc_attr_info_discover to discover the 128bit UUID.

  • Ok. Let me know if you have any further questions.

  • Hi,run_ar

     

    sd_ble_gattc_attr_info_discover(p_gattc_evt->conn_handle ,&ble_gattc_handle_range);

     

    I have tested the solution you gave,I simulated a way to find an unknown 128-bit uuid using function sd_ble_gattc_attr_info_discover(......) as following:

     

    I used SDK15\examples\ble_central\ble_app_hrs_c\pca10056 to find

    SDK15\examples\ble_peripheral\ble_app_uart\pca10056;

     

    I made some modifications to the filter condition of ble_app_hrs_c's function on_adv_report(.....), so that ble_app_hrs_c can be connected to ble_app_uart and at the same time, I added a new characteristic to ble_app_uart, so this ble_app_uart has a total of three characteristics.

    I added the function sd_ble_gattc_attr_info_discover(conn_handle , &ble_gattc_handle_range) to discovery_complete_evt_trigger() as follows:

     

    static void discovery_complete_evt_trigger(ble_db_discovery_t * p_db_discovery,

                                               bool                 is_srv_found,

                                               uint16_t             conn_handle)

    {

    .......

    .......

     

                if (m_pending_usr_evt_index == m_num_of_handlers_reg)

                {

                    // All registered modules have pending events. Send all pending events to the user

                    // modules.

                    pending_user_evts_send();

                    err_code = sd_ble_gattc_attr_info_discover(conn_handle , &ble_gattc_handle_range);

                }

                else

                {

                    // Too many events pending. Do nothing. (Ideally this should not happen.)

                }

    ........

    .........

    }

    Ble_gattc_handle_range is defined as

    ble_gattc_handle_range_t ble_gattc_handle_range =

    {

     0x0001,

     0xFFFF        

    };

     

    After that I got  BLE_GATTC_EVT_ATTR_INFO_DISC_RSP event ,I know I need to parse the pointer of type ble_gattc_evt_attr_info_disc_rsp_t (const ble_gattc_evt_attr_info_disc_rsp_t *attr_info_disc_rsp = &p_ble_evt->evt.gattc_evt.params.attr_info_disc_rsp;)

     

    But I don’t know how to parse attr_info_disc_rsp;I printed it after receiving BLE_GATTC_EVT_ATTR_INFO_DISC_RSP:

     

     NRF_LOG_DEBUG("BLE_GATTC_EVT_ATTR_INFO_DISC_RSP event");

                NRF_LOG_DEBUG("attr info discovery rsp count =%d",attr_info_disc_rsp->count);

                NRF_LOG_DEBUG("attr info discovery rsp format =%d",attr_info_disc_rsp->format);

    The result is confusing:

    <debug> ble_db_disc: BLE_GATTC_EVT_ATTR_INFO_DISC_RSP event

    <debug> ble_db_disc: attr info discovery rsp count =12

    <debug> ble_db_disc: attr info discovery rsp format =1

     

    attr_info_disc_rsp->count is 12,attr_info_disc_rsp->format =1,How to use the two parameters?

    In fact, the final feature I want to implement is to use the client to discover an unknown private service(unknown vendor UUID) (like nrf connect, there is no need to register uuid in advance).

  • Hi ,Sir

     

    I  did more tests about finding a private service with 128-bit uuid which are not present in the table provided to ble_vs_uuids_assign.

     

    I saw sd_ble_gattc_primary_services_discover(...) function. I saw the instructions for using this function. I found the following @note;

     

      * @note If any of the discovered services have 128-bit UUIDs which are not present in the table provided to ble_vs_uuids_assign, a UUID structure with

      * type @ref BLE_UUID_TYPE_UNKNOWN will be received in the corresponding event.

     

    The meaning here seems to be that this function is a 128-bit service that can be found without being registered in advance.  I tired to call the function to find the service mentioned earlier,but

    Always back a error NRF_ERROR_INVALID_PARAM,I don’t whyt,

    So please give some help ,what am i supposed to do for finding a private service with 128-bit uuid which are not present in the table provided to ble_vs_uuids_assign?

     

    Best wishes!

     

    Helen

Related