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

Advertising a group of services failed.

Hi,

I tried to combine BLE HRS & UART together on nrf51822. The service initialization code is

void advertising_init(void)
{
    uint32_t      err_code;
    ble_advdata_t advdata;
	
    uint8_t       flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

    ble_uuid_t adv_uuids[] = 
	{
		{BLE_UUID_BATTERY_SERVICE, 					BLE_UUID_TYPE_BLE},
		{BLE_UUID_HEART_RATE_SERVICE,				BLE_UUID_TYPE_BLE},		
		{BLE_UUID_DEVICE_INFORMATION_SERVICE, 		        BLE_UUID_TYPE_BLE},
		{BLE_UUID_NUS_SERVICE, 						m_nus.uuid_type}
	};

    // 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;
    advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    advdata.uuids_complete.p_uuids  = adv_uuids;

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

However, it failed and threw an error of NRF_ERROR_DATA_SIZE. What's wrong?

  • There is not enough space in advertising packet to contain all your sercives UUIDs. Just send all the UUIDs in scan response packet:

    void advertising_init(void)
    {
        uint32_t      err_code;
        ble_advdata_t advdata;
        ble_advdata_t scanrsp;
    
        uint8_t       flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    
        ble_uuid_t adv_uuids[] = 
        {
            {BLE_UUID_BATTERY_SERVICE,                  BLE_UUID_TYPE_BLE},
            {BLE_UUID_HEART_RATE_SERVICE,               BLE_UUID_TYPE_BLE},     
            {BLE_UUID_DEVICE_INFORMATION_SERVICE,               BLE_UUID_TYPE_BLE},
            {BLE_UUID_NUS_SERVICE,                      m_nus.uuid_type}
        };
    
        // 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(adv_uuids) / sizeof(adv_uuids[0]);
        scanrsp.uuids_complete.p_uuids  = adv_uuids;
    
        err_code = ble_advdata_set(&advdata, &scanrsp);
        APP_ERROR_CHECK(err_code);
    
    
    }
    
Related