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

Unable to change advertised data using ble_advdata_set().

I'm trying to change advertised manufacturing data during advertisement after pressing a button on the nRF52840 DK board.  Seen many examples using the call ble_advdata_set().  My set up does not recognize this function at all.  I need to change both advertisement data and service data upon a button press.

My initialization code looks like this:

static void advertising_init(void)
{
    ret_code_t                  err_code;

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

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

    adv_manuf_data.company_identifier = 0x0059;
    adv_manuf_data.data.p_data = (uint8_t *)&AdvData;
//    adv_manuf_data.data.size = sizeof(AdvData);
    adv_manuf_data.data.size = RI4_ADV_DATA_SIZE;   // For reasons unknown, sizeof(AdvData) returns 8 even though the structure is packed.

    init.advdata.p_manuf_specific_data   = &adv_manuf_data;

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

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

Code to change the advertisement data after a button press looks like this:

{
  ret_code_t  err_code;
  uint32_t Buffer=rand();

  LastAlert.Severity=Buffer & 0x3FFF; // Alert severity peaks at 0x3FFF
  LastAlert.Type=(Buffer >> 16) % 5;    // Limiting to 0-4

  AdvData.Flags|=IMPACT_STATUS_FLAG_ALERT;

  err_code = ble_advdata_set(&(init.advdata),NULL);

  APP_ERROR_CHECK(err_code);
}

Structures init and adv_manuf_data are global to allow them to be preserved.

The code will not compile with ble_advdata_set.  It cannot find this function, yet I see it used all over examples here.

Parents Reply Children
Related