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

Updating Advertising Data in SDK15

I would like to update my advertising data on the fly but actually it doesn't work. Many many posts talk about this behaviour, but no working answers.

Before SDK15, we use ble_advdata_set to changing the advertising data, so simple so easy work.

All of them suggest to use ble_advdata_encode and sd_ble_gap_adv_set_configure, but they returns error.

Please do not provide with other thread's link, because I have reviewed most of them. Also, I tired the the code in the example ble_app_beacon which includes codes for updating beacon's advertising data, but it ends up with failure.

Most of the advised code more or less like the following :

static ble_gap_adv_params_t m_adv_params;                                       /**< Parameters to be passed to the stack when starting advertising. */

static uint8_t      m_adv_handle            = BLE_GAP_ADV_SET_HANDLE_NOT_SET    /**< Advertising handle used to identify an advertising set. */

/**@brief Struct that contains pointers to the encoded advertising data. */
static ble_gap_adv_data_t m_adv_data =
{
    .adv_data =
    {
        .p_data = m_enc_advdata,
        .len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX
    },
    .scan_rsp_data =
    {
        .p_data = NULL,
        .len    = 0

    }
};



void advertising_update(void)
{
    for (uint8_t i = 0; i < my_URL_data.size; i++)
    {
        NRF_LOG_INFO("%d---%c    %d", i, my_URL_data.data[i], my_URL_data.data[i]);
    }
    
    
    
    
    
    uint32_t                err_code;
    ble_advdata_t   advdata;

    
    
    
    ble_uuid_t    adv_uuids[] = {{APP_EDDYSTONE_UUID, BLE_UUID_TYPE_BLE}};
    
    
    
    uint8_array_t eddystone_data_array;                             // Array for Service Data structure.
    /** @snippet [Eddystone data array] */
    eddystone_data_array.p_data = (uint8_t *) my_URL_data.data;   // Pointer to the data to advertise.
    eddystone_data_array.size   = my_URL_data.size;         // Size of the data to advertise.
    /** @snippet [Eddystone data array] */

    ble_advdata_service_data_t service_data;                        // Structure to hold Service Data.
    service_data.service_uuid   = APP_EDDYSTONE_UUID;                 // Eddystone UUID to allow discoverability on iOS devices.
    service_data.data               = eddystone_data_array;               // Array for service advertisement data.


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

    advdata.name_type               = BLE_ADVDATA_NO_NAME;
    advdata.include_appearance      = false;
    advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    
    advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    advdata.uuids_complete.p_uuids  = adv_uuids;
    
    advdata.p_service_data_array    = &service_data;                // Pointer to Service Data structure.
    advdata.service_data_count      = 1;
    
    
    
    // Initialize advertising parameters (used when starting advertising).
    ble_gap_adv_params_t m_adv_params;
    memset(&m_adv_params, 0, sizeof(m_adv_params));
    
    
    
    
    err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
    APP_ERROR_CHECK(err_code);
    
    err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, NULL);
    APP_ERROR_CHECK(err_code);
}

After so many threads, views, etc., still not getting the right solution ! Just want to ask from Nordic, why you removed the API "ble_advdata_set" ?

Related