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

When 128bit characteristic UUID is different form 128bit service UUID,how to discovery it?

I have the same problem as how to discovery 128bit characteristic UUID which is totally different form 128bit service UUID,the uuid in this question is the same with me,but I can not find solution .

I modified the ble_nus_c_init()  like this:

#define BASE_UUID                   {{0xfb,0x34,0x9b,0x5f,0x80,0x00,0x00,0x80,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00}}
#define BASE_UUID_FEE9              {{0xfb,0x34,0x9b,0x5f,0x80,0x00,0x00,0x80,0x00,0x10,0x00,0x00,0xe9,0xfe,0x00,0x00}}
#define BASE_UUID_CHAR_RX           {{0x00,0x96,0x12,0x16,0x54,0x92,0x75,0xb5,0xa2,0x45,0xfd,0xab,0x39,0xc4,0x4b,0xd4}}
#define BASE_UUID_CHAR_TX           {{0x01,0x96,0x12,0x16,0x54,0x92,0x75,0xb5,0xa2,0x45,0xfd,0xab,0x39,0xc4,0x4b,0xd4}}


uint32_t ble_nus_c_init(ble_nus_c_t * p_ble_nus_c, ble_nus_c_init_t * p_ble_nus_c_init)
{
    uint32_t      err_code;
    ble_uuid_t    uart_uuid,ble_uuid1,ble_uuid2;
    ble_uuid128_t nus_base_uuid =BASE_UUID;         //NUS_BASE_UUID;
    ble_uuid128_t base_uuid1 = BASE_UUID_CHAR_RX;
    ble_uuid128_t base_uuid2 = BASE_UUID_CHAR_TX;
    
    VERIFY_PARAM_NOT_NULL(p_ble_nus_c);
    VERIFY_PARAM_NOT_NULL(p_ble_nus_c_init);
    
    err_code = sd_ble_uuid_vs_add(&nus_base_uuid, &p_ble_nus_c->uuid_type);
    VERIFY_SUCCESS(err_code);

    uart_uuid.type = p_ble_nus_c->uuid_type;
    uart_uuid.uuid = 0xfee9;            //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->handles.nus_tx_handle = BLE_GATT_HANDLE_INVALID;
    p_ble_nus_c->handles.nus_rx_handle = BLE_GATT_HANDLE_INVALID;

    ble_db_discovery_evt_register(&uart_uuid);
    
    ble_uuid1.uuid = 0;    
    err_code = sd_ble_uuid_vs_add(&base_uuid1, &ble_uuid1.type);
    VERIFY_SUCCESS(err_code);

    ble_uuid2.uuid = 0;    
    err_code = sd_ble_uuid_vs_add(&base_uuid2, &ble_uuid2.type);
    VERIFY_SUCCESS(err_code);

    err_code=ble_db_discovery_evt_register(&ble_uuid1);
    err_code=ble_db_discovery_evt_register(&ble_uuid2);
    return err_code;
}

And I set NRF_SDH_BLE_VS_UUID_COUNT to 4 , modified the ram start and size.

I can't receive the event BLE_DB_DISCOVERY_COMPLETE, but  receive event  BLE_DB_DISCOVERY_ERROR and BLE_DB_DISCOVERY_SRV_NOT_FOUND

When I change 0xFEE9 to 0xFEE8 I can receive the event BLE_DB_DISCOVERY_COMPLETE,but characteristic.uuid.uuid = 0x00 I don't know why.

How to discovery 128bit characteristic UUID which is totally different form 128bit service UUID?

Can someone help me?

NRF52832   SDK14.2  code base "on ble_app_uart_c"   pca10040  s132

Thanks.

  • Also, the ble_uuid_t variables should be global to that file (i.e. your_service and your_characteristic), so that you have access to those variables in the db_evt_handler as well.

  • Hi Andy

    Thank you for your reply.

    I had modify my init function as you say , but still failed.

    This is my init code:

    #define HXJ_BASE_UUID                   {{0xfb,0x34,0x9b,0x5f,0x80,0x00,0x00,0x80,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00}}
    #define HXJ_BASE_UUID_FEE9              {{0xfb,0x34,0x9b,0x5f,0x80,0x00,0x00,0x80,0x00,0x10,0x00,0x00,0xe9,0xfe,0x00,0x00}}
    #define HXJ_BASE_UUID_CHAR_RX           {{0x00,0x96,0x12,0x16,0x54,0x92,0x75,0xb5,0xa2,0x45,0xfd,0xab,0x39,0xc4,0x4b,0xd4}}
    #define HXJ_BASE_UUID_CHAR_TX           {{0x01,0x96,0x12,0x16,0x54,0x92,0x75,0xb5,0xa2,0x45,0xfd,0xab,0x39,0xc4,0x4b,0xd4}}
    
    uint32_t ble_nus_c_init(ble_nus_c_t * p_ble_nus_c, ble_nus_c_init_t * p_ble_nus_c_init)
    {
        uint32_t      err_code;
        ble_uuid_t    uart_uuid;
        ble_uuid128_t nus_base_uuid =HXJ_BASE_UUID;//NUS_BASE_UUID;
        
        ble_uuid128_t   service_base_uuid = HXJ_BASE_UUID_FEE9;
        ble_uuid128_t   characteristicRX_base_uuid = HXJ_BASE_UUID_CHAR_RX;
        ble_uuid128_t   characteristicTX_base_uuid = HXJ_BASE_UUID_CHAR_TX;
        
        VERIFY_PARAM_NOT_NULL(p_ble_nus_c);
        VERIFY_PARAM_NOT_NULL(p_ble_nus_c_init);
        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->handles.nus_tx_handle = BLE_GATT_HANDLE_INVALID;
        p_ble_nus_c->handles.nus_rx_handle = BLE_GATT_HANDLE_INVALID;
    
        APP_ERROR_CHECK(sd_ble_uuid_vs_add(&service_base_uuid, &serviceFEE9.type));
        APP_ERROR_CHECK(sd_ble_uuid_vs_add(&characteristicRX_base_uuid, &charRX.type));
        APP_ERROR_CHECK(sd_ble_uuid_vs_add(&characteristicTX_base_uuid, &charTX.type));
        
        serviceFEE9.uuid=0xfee9;
        charRX.uuid=0x0;
        charTX.uuid=0x0;
        
        APP_ERROR_CHECK(ble_db_discovery_evt_register(&serviceFEE9));
        
        return err_code;
    }

    All of the four 128bit UUID ,I can get it by nRF Connect APP. Red mark is UUID.

    I tried a lot of values for serviceFEE9.uuid、charRX.uuid and charTX.uuid in the init function。But in the ble_nus_c_on_db_disc_evt() , the value of p_evt->evt_type has not been BLE_DB_DISCOVERY_COMPLETE.(often 0x01、0x02、0x010A)

    But in the nRF Connect APP , I can receive data when I click the blue mark.

    Look forward to your reply

  • If you get 0x01 as the event type that indicates that you're getting a SoftDevice error somewhere. What's the error code you get? You can check it in p_evt->params.err_code

  • Hi 

    I am not sure under what circumstances 0x01 will appear.This seems to be related to different UUID I set.

    I tested it a few times, but 0x01 did not appear.May be that my parameter error occurred during the test.

    When I get 0x02, the  p_evt->params.err_code looks like uuid.type<<8|16bit uuid.

    What I want to know is why I can read the 128bit characteristi UUID by nRF Connect APP but I can't discover it by the function ble_db_discovery_start().Even though I have added the 128bit uuid to the list.

  • If you don't get 0x01 you're not getting any errors. 0x02 means that the service was not found. The error code is in a union, so what you're seeing is actually the UUID in params.discovered_db, not the err_code.

    Is that the only service you're trying to discover? Have you successfully discovered other services before? How are you starting the discovery?

Related