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

Is there the turn of Advertise and Service initalize ?

I tried to work application. But firmware stops at advertising_init(). When I exchange advertising_init() and services_init(), firmware does not stop. why ?

S110 v8.0.0
SDK v8.1.0

[NG code in main()]

ble_stack_init();
gap_params_init();
advertising_init();  <-----
services_init();     <-----
conn_params_init();
application_timers_start();
err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(err_code);

[OK code in main()]

ble_stack_init();
gap_params_init();
services_init();     <-----
advertising_init();  <-----
conn_params_init();
application_timers_start();
err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(err_code);

static void advertising_init(void) {

uint32_t err_code;
ble_advdata_t advdata;
ble_advdata_t scanrsp;

memset(&advdata, 0, sizeof(advdata));
advdata.name_type          = BLE_ADVDATA_FULL_NAME;
advdata.include_appearance = true;
advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
advdata.uuids_complete.p_uuids  = m_adv_uuids;

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

ble_adv_modes_config_t options = {0};
options.ble_adv_fast_enabled  = BLE_ADV_FAST_ENABLED;
options.ble_adv_fast_interval = APP_ADV_INTERVAL;
options.ble_adv_fast_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;

err_code = ble_advertising_init(&advdata, &scanrsp, &options, on_adv_evt, NULL);
APP_ERROR_CHECK(err_code);

}

static void services_init(void) {

uint32_t err_code;
ble_nus_init_t nus_init;
ble_dis_init_t dis_init;

memset(&nus_init, 0, sizeof(nus_init));
nus_init.data_handler = nus_data_handler;
err_code = ble_nus_init(&m_nus, &nus_init);
APP_ERROR_CHECK(err_code);

memset(&dis_init, 0, sizeof(dis_init));
ble_srv_ascii_to_utf8(&dis_init.manufact_name_str, (char*)MANUFACTURER);
ble_srv_ascii_to_utf8(&dis_init.model_num_str, MODEL_NUM);
ble_srv_ascii_to_utf8(&dis_init.hw_rev_str, HW_REV);
ble_srv_ascii_to_utf8(&dis_init.fw_rev_str, FW_REV);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&dis_init.dis_attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&dis_init.dis_attr_md.write_perm);
err_code = ble_dis_init(&dis_init);
APP_ERROR_CHECK(err_code);

}

  • No the firmware doesn't stop, it's somewhere doing something. What are the two values of err_code before the APP_ERROR_CHECK()s? If they aren't zero, then one or other of them failed with an error code telling you why.

  • Is this Nordic example or yours? I have faced same behavior few months ago and i saw that i have to initialize services first before advertising_init(). I didn't ask anyone then, but i believe it had to do something that i was putting my own custom service UUID in the advertisement packet. So i was trying to put that service UUID in the advertising packet, but the service wasn't initialized yet. So calling services_init(), before advertising_init() fixed that. Then you don't have this problem in Nordic examples, because they are using services which are defined by Bluetooth SIG and their UUIDs are known before initializing those services. Could be great if someone could confirm that my speculations here are correct.

  • Thank you for your reply. I checked err_code. It was 0x00000007. I tracked this program; advertising_init() --> ble_advertising_init() --> ble_advdata_set() --> adv_data_encode() for "Encode scan response data" --> uuid_list_encode() for "Encode 'complete' uuid list" --> uuid_list_sized_encode() for "Encode 16 bit UUIDs"" --> sd_ble_uuid_encode() err_code = 0x00000007

    Parameter of sd_ble_uuid_encode(&uuid, &encode_size, NULL); uuid=0x20003B14, uuid[0]=0x0001, uuid[1]=0x02, encode_size=0x02

    I think that it is correct the parameter of sd_ble_uuid_encode(). What will be wrong ?

  • Thank you for your reply. I used some Nordic Samples (HR sense sample and NUS sample). I started a project from using NUS sample. I want to include DFU code, and used HR sense sample. I found a different from advertising_init() position in main(). Then I got Error ! I checked that NUS is working. But I don't execute HR sense sample. Sorry.

    1. HR sense nRF51_SDK_8.1.0_b6ed55f\examples\ble_peripheral\ble_app_hrs

    2. NUS nRF51_SDK_8.1.0_b6ed55f_original\examples\ble_peripheral\ble_app_uart

  • so you are encoding 16 bit UUID, but your uuid=0x20003B14? Thats 32-bit. error code itself 0x00000007 stands for NRF_ERROR_INVALID_PARAM, means you passed invalid parameter to the function.

Related