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

how to update the advertisement packet

hi ...

how to update the advertisement  packet .. I have seen many post regarding this ,I am not getting clear , anyone can share me the piece of code which will help me 

  • Hello,

    Which SDK version are you working with?
    Are you planning to use the Advertising library?
    If so, the easiest way to go about updating the advertising data is to use the ble_advertising_advdata_update function.

    If you are using an SDK version older than v.17, you will need to store two different advertising data buffers, and alternate between which data advdata buffer you provide the _advdata_update function.
    I.e you may not provide the advdata_update function with the same ( but modified ) advdata buffer that you provided during the last call to advdata_update.
    If you are using SDK version >= v.17 then the advdata_update function handles this for you.

    If you are working with an older SDK version, you might also benefit from reading the discussion in this ticket.

    Best regards,
    Karl

  • hi ,

    karl Ylvisaker 

    I  am using 15.2 verion sdk . I Have created two buffers ..kindly check my code , is this correct ? correct me if were wrong And also explain how to use the advertise update function in 17 version sdk

    static ble_gap_adv_data_t m_adv_data1 =
    {
        .adv_data =
        {
            .p_data = m_raw_data_buffer1,
            .len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX
        },
        .scan_rsp_data =
        {
            .p_data = NULL,
            .len    = 0
    
        }
    };
    static ble_gap_adv_data_t m_adv_data2 =
    {
        .adv_data =
        {
            .p_data = m_raw_data_buffer2,
            .len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX
        },
        .scan_rsp_data =
        {
            .p_data = NULL,
            .len    = 0
    
        }
    };
    

    static advertising_init()
    
    {
    ......
    .....
    
      memset(&advdata, 0, sizeof(advdata));
    
        advdata.name_type             = BLE_ADVDATA_NO_NAME;
        advdata.flags                 = flags;
        advdata.p_manuf_specific_data = &manuf_specific_data;
    
        // Initialize advertising parameters (used when starting advertising).
        memset(&m_adv_params, 0, sizeof(m_adv_params));
    
        m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
        m_adv_params.p_peer_addr     = NULL;    // Undirected advertisement.
        m_adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
        m_adv_params.interval        = NON_CONNECTABLE_ADV_INTERVAL;
        m_adv_params.duration        = 0;       // Never time out.
    
        err_code = ble_advdata_encode(&advdata, m_adv_data1.adv_data.p_data, &m_adv_data1.adv_data.len);
        APP_ERROR_CHECK(err_code);
    
        err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data1, &m_adv_params);
        APP_ERROR_CHECK(err_code);

    static advertising_update()
    {
    
    
    _ _ _ _ _
     _ _ _
     
     
     err_code = ble_advdata_encode(&advdata, m_adv_data2.adv_data.p_data, &m_adv_data2.adv_data.len);
        APP_ERROR_CHECK(err_code);
    
        err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data2, NULL);
        APP_ERROR_CHECK(err_code);

  • Hello again,

    ps_anu said:
    I  am using 15.2 verion sdk . I Have created two buffers ..kindly check my code , is this correct ?

    What happens when you try to run this code? Does it update your advertising data?
    The general approach looks correct, but I suspect that you have cut out some parts of the functions' code, so I can not say anything for certain.

    ps_anu said:
    also explain how to use the advertise update function in 17 version sdk

    The ble_advertising_advdata_update function updates the advertising and scan response data related to an advertising handle.
    If advertising has already started, it updates the advertising data without stopping and starting advertising.
    In SDK v.17.0.0 it is implemented like the following:

    ret_code_t ble_advertising_advdata_update(ble_advertising_t   * const p_advertising,
                                              ble_advdata_t const * const p_advdata,
                                              ble_advdata_t const * const p_srdata)
    {
        VERIFY_PARAM_NOT_NULL(p_advertising);
        if (p_advertising->initialized == false)
        {
            return NRF_ERROR_INVALID_STATE;
        }
    
        if ((p_advdata == NULL) && (p_srdata == NULL))
        {
            return NRF_ERROR_NULL;
        }
    
        ble_gap_adv_data_t new_adv_data;
        memset(&new_adv_data, 0, sizeof(new_adv_data));
    
        if (p_advdata != NULL)
        {
            new_adv_data.adv_data.p_data =
                (p_advertising->p_adv_data->adv_data.p_data != p_advertising->enc_advdata[0]) ?
                 p_advertising->enc_advdata[0] : p_advertising->enc_advdata[1];
            new_adv_data.adv_data.len = adv_set_data_size_max_get(p_advertising);
    
            ret_code_t ret = ble_advdata_encode(p_advdata,
                                                new_adv_data.adv_data.p_data,
                                                &new_adv_data.adv_data.len);
            VERIFY_SUCCESS(ret);
        }
    
        if (p_srdata != NULL)
        {
            new_adv_data.scan_rsp_data.p_data =
                (p_advertising->p_adv_data->scan_rsp_data.p_data != p_advertising->enc_scan_rsp_data[0]) ?
                 p_advertising->enc_scan_rsp_data[0] : p_advertising->enc_scan_rsp_data[1];
            new_adv_data.scan_rsp_data.len = adv_set_data_size_max_get(p_advertising);
    
            ret_code_t ret = ble_advdata_encode(p_srdata,
                                                new_adv_data.scan_rsp_data.p_data,
                                                &new_adv_data.scan_rsp_data.len);
            VERIFY_SUCCESS(ret);
        }
    
        memcpy(&p_advertising->adv_data, &new_adv_data, sizeof(p_advertising->adv_data));
        p_advertising->p_adv_data = &p_advertising->adv_data;
    
        return sd_ble_gap_adv_set_configure(&p_advertising->adv_handle,
                                            p_advertising->p_adv_data,
                                            NULL);
    }



    Best regards,
    Karl

  • thanks for your response , where i should include my new updating data ?   and how to assign to 

  • No problem at all, I am happy to help!

    ps_anu said:
    where i should include my new updating data ?   and how to assign to 

    I do not understand what you mean by this.
    You should set the contents of your m_adv_data2 at the start of your advertising_update function ( or if it is two static advertising data buffers, initialize them to the correct values ).

    Best regards,
    Karl

Related