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

Parents
  • 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

Reply
  • 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

Children
  • 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