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);

}

Parents
  • 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.

Reply
  • 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.

Children
No Data
Related