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

Question about UUID with ble_db_discovery_evt_register()

I'm developing a central that discovers services in a peripheral.  The services are both custom and standard BLE services.  Discovery is working fine, but there is one issue I'm unsure of:  when calling ble_db_discovery_evt_register, a UUID of type ble_uuid_t is passed as an argument.  When discovering standard services with 16-bit UUIDs, this makes sense, but when discovering custom services with 128-bit UUIDs, what value should be used here?  I'm using sd_ble_uuid_vs_add for the custom services, but I've found that custom services are only discovered when I set the UUID passed to ble_db_discovery_evt_register to 1.

Parents
  • Take a look at the ble_app_uart_c example and the function ble_nus_c_init() in ble_nus_c.c, which illustrates how to use 128-bit UUID's. I've provided the code down below with comments:

    // Add a Vendor Specific 128-bit base UUID to the BLE stack table
    // p_ble_nus_c->uuid_type will be equal to BLE_UUID_TYPE_VENDOR_BEGIN after the call
    err_code = sd_ble_uuid_vs_add(&nus_base_uuid, &p_ble_nus_c->uuid_type);
    VERIFY_SUCCESS(err_code);
    
    //Set uart_uuid.type equal to BLE_UUID_TYPE_VENDOR_BEGIN
    uart_uuid.type = p_ble_nus_c->uuid_type;
    // Set uart_uuid.uuid equal to BLE_UUID_NUS_SERVICE (16 bit UUID), which
    // will be equal to byte 12 and 13 of the base UUID set eariler
    uart_uuid.uuid = BLE_UUID_NUS_SERVICE;
    
    p_ble_nus_c->conn_handle           = BLE_CONN_HANDLE_INVALID;
    p_ble_nus_c->evt_handler           = p_ble_nus_c_init->evt_handler;
    p_ble_nus_c->error_handler         = p_ble_nus_c_init->error_handler;
    p_ble_nus_c->handles.nus_tx_handle = BLE_GATT_HANDLE_INVALID;
    p_ble_nus_c->handles.nus_rx_handle = BLE_GATT_HANDLE_INVALID;
    p_ble_nus_c->p_gatt_queue          = p_ble_nus_c_init->p_gatt_queue;
    
    return ble_db_discovery_evt_register(&uart_uuid);

    Best regards,

    Simon

  • // Set uart_uuid.uuid equal to BLE_UUID_NUS_SERVICE (16 bit UUID), which
    // will be equal to byte 12 and 13 of the base UUID set eariler
    uart_uuid.uuid = BLE_UUID_NUS_SERVICE;

    BLE_UUID_NUS_SERVICE is 1, but there is no "1" anywhere in the base UUID (NUS_BASE_UUID), so I still don't understand where the "1" is coming from.

Reply Children
Related