Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

How to get data from Unknown Service

Hello. I am trying to get data from BLE sensors. Sensors work like Nordic uart service. Main problem is that every BLE sensor has different 128-bit UUID of that service. If i use central nus example from nRF5 SDK and change NUS_BASE_UUID to  128-bit UUID of one sensor - it works well. But if take another sensor it doesnot work, because it has another 128 bit UUID. How can i handle that case if i dont know 128-bit UUID of the service?

  • Hello Dima,

    Thanks for your query.

    Central needs performing service discovery after connecting to the BLE device to know which service is available ( which should provides the UUID). And the central device needs to have information of the BLE service in order to read it. 

    From the SoftDevice v.7.2.0, this feature has been improved. You have to enable the BLE_GATTC_OPT_UUID_DISC option to discover 128 bit UUIDS more efficiently. This option enables the automatic insertion of discovered 128 bit UUIDs to the vendor specific UUID table. 

    You can find this here: sdk_17_2.0_folder\ components\softdevice\s140\doc

    Hope it helps.

    Best Regards,

    Kazi Afroza Sultana

  • I dont know how to use your information. What example should i see or what tutorial should i read to understand what you are talking about?

  • Hello Dima,

    We do not have any direct tutorial for it. Since I mentioned in my previous message that is one of the new features of s140_nrf52_7.2.0 when migrating from s140_nrf52_7.0.1. 

    However, here is the technique from our expat which can be added in the existing example ble_app_uart_c (SDK17.0.2\examples\ble_central\ble_app_uart_c). Inside this code you can see that the discovery is started in the BLE_GAP_EVT_CONNECTED in the ble_evt_handler() by using ble_db_discovery_start. Then the discovery event handler is set in db_discovery_init() function and it is set to db_disc_handler().

    This call back forwards the event to ble_nus_c_on_db_disc_evt() in ble_nus_c.c (17.1.0\components\ble\ble_services\ble_nus_c\ble_nus_c.c). And that is the event that checks the UUID. So, it checks if the device has the nus UUID:

    // Check if the NUS was discovered.
        if (    (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE)
            &&  (p_evt->params.discovered_db.srv_uuid.uuid == BLE_UUID_NUS_SERVICE)
            &&  (p_evt->params.discovered_db.srv_uuid.type == p_ble_nus_c->uuid_type))

    Whatever UUID is being looked for will be present in this this event. We think this callback will trigger once for every service, and it contains an array of all the characteristics. 

    Thanks.

     Best Regards,

    kazi Afroza Sultana

  • Thank you for your answer, but main problem is that p_evt->params.discovered_db.srv_uuid.uuid is 16 Bit UUID, but i need 128 bit UUID. If i use sd_ble_gattc_primary_services_discover i also receive only 16 Bit UUIDs of services. How can i get 128 bit UUID? 

  • Hello Dima,

    You can add this new functionality (sd_ble_opt_set(BLE_GATTC_OPT_UUID_DISC, &(ble_opt_t){.gattc_opt.uuid_disc.auto_add_vs_enable = 1});) which is described in the migration document

    in the ble_app_uart example after iniitalization of soft device. 

    static void ble_stack_init(void)

    {

    ret_code_t err_code;

    err_code = nrf_sdh_enable_request();

    APP_ERROR_CHECK(err_code);

    //configure the BLE stack using the default settings. Fetch the start address of the application RAM .

    uint32_t ram_start = 0;

    err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);

    APP_ERROR_CHECK(err_code);

    //Enable BLE stack

    err_code = nrf_sdh_ble_enable(&ram_start);

    APP_ERROR_CHECK(err_code);

    //Register a handler for BLE events

    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);

    err_code = sd_ble_opt_set(BLE_GATTC_OPT_UUID_DISC, &(ble_opt_t){.gattc_opt.uuid_disc.auto_add_vs_enable = 1}); // (this line is from the migration document-improved functionality)

    APP_ERROR_CHECK(err_code);

    }

    Could you please try and see what is the consequence. Please let us know.

    Best Regards 

    Kazi Afroza Sultana

Related