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,

    So if I understand you correctly you do a sd_ble_gattc_primary_services_discover, and the return event is BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP. this contains a service where ble_gattc_service_t -> ble_uuid_t -> type is unknown?

    If that is the case you should call sd_ble_gattc_attr_info_discover and provide the ble_gattc_service_t -> ble_gattc_handle_range_t to this function.

    If you do this correctly you should get an event called BLE_GATTC_EVT_ATTR_INFO_DISC_RSP. This will have the structure ble_gattc_evt_attr_info_disc_rsp_t. In this case the format should be

    #define  BLE_GATTC_ATTR_INFO_FORMAT_128BIT   2

    Based on the format and the count you can parse the UUID.

  • Hi,Sir:

    Answer 1

    Sir,I would have to say ble_gattc_service_t -> ble_uuid_t -> type This function is only included in the ble_gattc_evt_rel_disc_rsp_t structure. It is valid when the BLE_GATTC_EVT_REL_DISC_RSP is returned. I have tested again,there was no BLE_GATTC_EVT_REL_DISC_RSP event. Still, I printed the information for ble_gattc_service_t -> ble_uuid_t -> type after receiving BLE_GATTC_EVT_REL_DISC_RSP event

     

     NRF_LOG_DEBUG("includes a 0x%04X type service UUID 0x%04X",

            p_ble_gattc_evt->params.rel_disc_rsp.includes[0].included_srvc.uuid.uuid,

            p_ble_gattc_evt->params.rel_disc_rsp.includes[0].included_srvc.uuid.type);

     

    The result i s always not current:

     

    <debug> ble_db_disc: includes  0 service

    <debug> ble_db_disc: includes a 0x0520 type service UUID 0x0018

    Or

    <debug> ble_db_disc: includes  0 service

    <debug> ble_db_disc: includes a 0x2902 type service UUID 0x0001

    Do I need to call this function sd_ble_gattc_relationships_discover(....), how to call it to get the handle range of the correct unknown private service

     

    I have some tests on this function sd_ble_gattc_primary_services_discover:

    This function has different results under different initialization conditions (sd_ble_uuid_vs_add() initialization) and input parameters. The following are the cases:

    • > add a 128bit based uuid by using sd_ble_uuid_vs_add, if the 128 bit base uuid of Client and peripheral is exactly the same, and the service UUID (12, 13byte) is the same, you can find the service and features normally when you call sd_ble_gattc_primary_services_discover(... When you get a normal BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP  with BLE_GATT_STATUS_SUCCESS 0x0000 ;otherwise you get a normal BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP with BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND        0x010A

     

    • >  no  adding add a 128bit based uuid by using sd_ble_uuid_vs_add,call the function(uuid.type = BLE_UUID_TYPE_UNKNOWN  or uuid.type = 2),the function return an error code NRF_ERROR_INVALID_PARAM immediately without BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP event.

     

    Answer 2

    Since I don't know the range of the ble_gattc_handle_range_t handle (I mean when the Client host finds an unknown 128-bit private service),so my ble_gattc_handle_range_t start with 0x0001,end with 0xFFFF; After calling sd_ble_gattc_attr_info_discover function multiple times in succession,every time this function is called, start_handle is incremented by 1; I finally goty attr_info_disc_rsp->format =2 and I got 128 bit uuid.Even though I got the results I wanted, I don't understand why, it seems to be a call, I can only get one Attritube (because format has one, and count returns more than one)

     

     

    In short, what I’d like to achieve is a complete discovery of an unknown private service with 128bit uuid and communication with this service (just support notify).Cloud you please give some suggestions and solutions for this function?

  • Not sure why you are talking about BLE_GATTC_EVT_REL_DISC_RSP?

    1. You need to check the ble_gattc_evt_prim_srvc_disc_rsp_t

    This will contain a Count and a ble_gattc_services_t structure. If you look at this structure you see it contains a ble_uuid_t structure. if this type is BLE_UUID_TYPE_UNKNOWN you need to move on to 2, and provide the handle range provided as part of the ble_gattc_evt_prim_srvc_disc_rsp_t event.

    2. You are not supposed to iterate through the all the handles. Please check the handle range that is returned together with the unknown UUID type.

  • OK, I will retest that in SDK15.2,Thanks!

  • Good luck, let me know if you have any further questions.

Related