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

Why do have two advertising_init() function co-exist?

I am working with SDK 14.0 . I see two "type" of advertising_init() function :

1-

static void advertising_init(void)
{
    uint32_t               err_code;
    ble_advertising_init_t init;

    memset(&init, 0, sizeof(init));

    init.advdata.name_type          = BLE_ADVDATA_FULL_NAME;
    init.advdata.include_appearance = false;
    init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;

    init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.srdata.uuids_complete.p_uuids  = m_adv_uuids;

    init.config.ble_adv_fast_enabled  = true;
    init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
    init.config.ble_adv_fast_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;

    init.evt_handler = on_adv_evt;

    err_code = ble_advertising_init(&m_advertising, &init);
    APP_ERROR_CHECK(err_code);

    ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
}

this function use ble_advertising_init_t variable.

2 static void advertising_init(void) { ret_code_t err_code; ble_advdata_t advdata; ble_advdata_t srdata;

ble_uuid_t adv_uuids[] = {{LBS_UUID_SERVICE, m_lbs.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              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;


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

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

}

this function use two ble_advdata_t variables. who can tell me what different between them? and how can I convert between them?

Parents
  • Hello MainOFF

    I am not quite sure what you're referring to here. The second function you post is not related to advertising, but to initializing the preferred connection parameters, and does not contain any ble_advdata_t variables. Have you posted the wrong function?

    That said there are a couple of variations of the advertise_init function.

    1. Static void advertise_init(void) – static: can only be called within main.c, void: does not return a value, (void) no arguments accepted.

    2. Static uint32_t advertising_init(uint8_t adv_flags) – static: see above, uint32_t returns a 32 bit value on completion which is used for error checks, (uint8_t adv_flags) an 8 bit value accepted as argument.

    Which one of these you use depend on what you need or prefer. Number 1 is typically used in the normal applications examples and error checks are performed within the function, number 2 is used in the dfu code and accepts information on what advertise flags to set. These advertise functions are merely used to organize your code in a reasonable way and can be modified as you need.

    The advertise_init function for beacons have two ble_advdata_t variables as you mention

    ble_advdata_t advdata;
    ble_advdata_t srdata;
    

    where advdata is the advertisement data the beacon typically sends out, and srdata is the scan response data, additional data transmitted upon request from an observer.

    For more information on advertisement data see this tutorial.

    Best regards

    Jørn Frøysa

  • Sorry ! maybe I was so confused ! I was posted again :(

Reply Children
No Data
Related