This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Error in "is_UUID_present"

Hi!

I want to connect a nrf51 dk with a beacon and I'm using the UUID to make the connection. In the beacon code I define the UUID in this way:

ble_uuid_t adv_uuids[] = {{BCS_UUID_SERVICE, m_bcs.uuid_type}};
ble_uuid_t m_adv_uuids[]= {BLE_UUID_OUR_SERVICE_UUID,BLE_UUID_TYPE_VENDOR_BEGIN}; //aggiunta da noi
// Build and set advertising data
memset(&advdata, 0, sizeof(advdata));
advdata.name_type               = BLE_ADVDATA_FULL_NAME;
advdata.include_appearance      = true;
advdata.flags.size              = sizeof(flags);
advdata.flags.p_data            = &flags;

memset(&scanrsp, 0, sizeof(scanrsp));
scanrsp.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
scanrsp.uuids_complete.p_uuids  = m_adv_uuids;

err_code = ble_advdata_set(&advdata, &scanrsp);
APP_ERROR_CHECK(err_code);

In the nrf51 I use the function is_UUID_present and I get the error NRF_ERROR_NOT_FOUND (for a 128bit UUID no match in the populated table of UUIDs ) and the code that I use is

else if ( (field_type == BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE)
            || (field_type == BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE)
            )
{
                    
    err_code = sd_ble_uuid_decode(UUID128_SIZE, 
                                  &p_data[index + 2], 
                                  &extracted_uuid);
    if (err_code == NRF_SUCCESS)
    {    
        if ((extracted_uuid.uuid == p_target_uuid->uuid)
            && (extracted_uuid.type == p_target_uuid->type))
        {
               return true;
        }
    }
                    
}

Can someone explain me why this happens? Thank you so much! projects.rar

  • The only thing I can think of is that your BLE_UUID_OUR_SERVICE_UUID is not the BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE or BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE type. Can you sniff your advertisement packets to see if it is transmitting as 128BIT UUID AD_Type?

  • I see from the Android App an 128bit UUID, I have followed this tutorial to create it devzone.nordicsemi.com/.../ I have a question: if I would like to write in the code directly the UUID that I see in the app, which kind of variable should I use?and how to exactly write it inside the code?

  • Sorry if I continue on posting, but there's a possibility that something is wrong with is_uuid_present ? Because I create the service as in the tutorial, I can see the UUID from the mobile phone but I can't establish a connection using the UUID because is_uuid_present gives me error

  • Hi,

    I think the problem is on the central side. Since you are using is_uuid_present() I assume that you base your code on the ble_app_uart_c example? You need to add your beacon base UUID with its 16-bit service UUID to the table of UUIDs in ble_nus_c_init() located in ble_nus_c.c. The method is almost identical to the method used in the tutorial.

    EDIT 1: Modify ble_nus_c_init() to look like this:

    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 = BLE_UUID_OUR_BASE_UUID; // NORDIC: Use our base UUID instead
            
        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 = BLE_UUID_OUR_SERVICE; // NORDIC: Use our service UUID instead
        
        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_rx_handle = BLE_GATT_HANDLE_INVALID;
        p_ble_nus_c->handles.nus_tx_handle = BLE_GATT_HANDLE_INVALID;
        
        return ble_db_discovery_evt_register(&uart_uuid);
    }
    

    You also need to modify the static const ble_uuid_t m_nus_uuid variable located almost at the top of main.c:

    static const ble_uuid_t m_nus_uuid = 
    {
        .uuid = BLE_UUID_OUR_SERVICE,
        .type = BLE_UUID_TYPE_VENDOR_BEGIN
    };
    

    EDIT 2: Modified ble_app_uart_c example that works with finished service tutorial code: 77683-ble_app_uart_c

    EDIT 3: Example is for SDK 11. Search for "// NORDIC" to see what I have modified.

    EDIT 4: I have looked at your code and I think I have found the issue. After I compiled and ran your beacon code I could see that you are not advertising the the correct vendor specific UUID. You have actually placed the DFU UUID in your scan response, not the BLE_UUID_OUR_BASE_UUID. The root cause is found in advertising_init() and services_init() in the Beacon project. In services_init() you initiate three services; dfu, bcs, and our service. All three services add a 128-bit UUID to the table of UUIDs in the BLE stack, and BLE_UUID_OUR_BASE_UUID is the third UUID to be added to the table. So the solution is simply to change this line in advertising_init():

    ble_uuid_t m_adv_uuids[]= {BLE_UUID_OUR_SERVICE,BLE_UUID_TYPE_VENDOR_BEGIN};
    

    to this:

    ble_uuid_t m_adv_uuids[]= {BLE_UUID_OUR_SERVICE,BLE_UUID_TYPE_VENDOR_BEGIN + 2};
    

    then you will put the third 128-bit UUID into your scan response packet. That was the only change I had to make to get your code working (after altering the ble_nus_c.c file as above of course).

  • Yes my base code is the ble_app_uart_c. Do you mean that I have to paste the declaration of my service UUID inside ble_nus_c_init?

    ble_uuid_t        service_uuid;
        ble_uuid128_t     base_uuid = BLE_UUID_OUR_BASE_UUID;
        service_uuid.uuid = BLE_UUID_OUR_SERVICE_UUID;
    err_code = sd_ble_uuid_vs_add(&base_uuid, &service_uuid.type);
        APP_ERROR_CHECK(err_code);
    
Related