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

Porting ble_nus service from sdk 6.0 to 6.1 on nrf51822

Hi Nordic Expert,

Recently I wanna run ble_nus service on my nrf51822 platform, you know, sdk 6.0 does have this demo code in s110 directory, but from sdk 6.1 I cann't see it any more. So I try porting it from 6.0 to 6.1. No luck that I got an strange issue when ble begins advertising.

See below code snippet, after nus service is init'd (Nordic UUID should be registered), it goes to this advertising_init funtion. You know, to let upper App know what services are supportted, I have to put my services here, right? But it's weird that each time ble_advdata_set returns with error num and then system reste. But if I replaced nus service UUID as other SIG service, e.g. TX power service, this can work noramally, I can see adverting led is liting. I am so confused what's wrong there? Would you help me?

void advertising_init(uint8_t adv_flags) { uint32_t err_code; ble_advdata_t advdata; ble_advdata_t scanrsp;

ble_uuid_t adv_uuids[] = { //{BLE_UUID_TX_POWER_SERVICE, BLE_UUID_TYPE_BLE}, {BLE_UUID_NUS_SERVICE, BLE_UUID_TYPE_VENDOR_BEGIN}, };

m_advertising_mode = BLE_NO_ADV;

// Build and set advertising data
memset(&advdata, 0, sizeof(advdata));

advdata.name_type               = BLE_ADVDATA_FULL_NAME;
advdata.include_appearance      = false;
advdata.flags.size              = sizeof(adv_flags);
advdata.flags.p_data            = &adv_flags;
	
memset(&scanrsp, 0, sizeof(scanrsp));
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);

}

  • So you've found that ble_advdata_set() returns with an error code, good, did you look up the error code to see what it means? Is it perhaps NRF_ERROR_DATA_SIZE (0x0c)? If you look in the documentation it will tell you ..

     *  @return    
     *  NRF_SUCCESS on success, NRF_ERROR_DATA_SIZE if not all the requested data could fit
     *  into the advertising packet. The maximum size of the advertisement packet is @ref
     *  BLE_GAP_ADV_MAX_SIZE.
    

    BLE UUIDS are short 2 bytes, vendor UUIDs are long 16 bytes, that's 14 bytes extra.

    Send a shorter device name, or none at all, or put the service UUID in the scan response

Related