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?

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

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

Children
Related