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

How to update advertisement packet SDK 15.0.0 ?

Dear all,

I am trying to develop an application that reads data from a sensor (accelerometer) and I want to be able to update the advertisement packet with the measurement I obtain from it.

So far I am able to read the values from the sensor. Using this example as a basis I can transmit a single value, but I am unable to update the content of the package in order to be able to read the right value. Is there any idea, how I can do this update?

I am using SDK 15.0.0.0. From what I have seen in the forum there is no straight forward way to do this, but I wonder, if someone has the same issue and if it is possible to share some sample code with me.

Kind regards

Parents
  • HI,

    You can refer to my example at https://github.com/jimmywong2003/nrf5-modify-device-parameter-through-host/blob/modify_non_connectable_advertising/ble_app_change_advertising_example/main.c

    I hardcode the enc_advdata (advertising data) and set the adv data with pointer.

    and then update the battery info (fill up the 1st byte of advdata) in the ADV payload.

            m_adv_data.adv_data.p_data = m_hardcode_enc_advdata;
            m_adv_data.adv_data.len    = 0x1F; // hardcode to 31 bytes
    
            err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);
            APP_ERROR_CHECK(err_code);

    void saadc_event_handler(nrf_drv_saadc_evt_t const * p_event)
    {
            if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
            {
                    nrf_saadc_value_t adc_result;
                    uint16_t batt_lvl_in_milli_volts;
                    // uint8_t percentage_batt_lvl;
                    uint32_t err_code;
    
                    adc_result = p_event->data.done.p_buffer[0];
    
                    err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, 1);
                    APP_ERROR_CHECK(err_code);
    
                    batt_lvl_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(adc_result) +
                                              DIODE_FWD_VOLT_DROP_MILLIVOLTS;
                    m_percentage_batt_lvl = battery_level_in_percent(batt_lvl_in_milli_volts);
    
    #if defined(USE_THINGY_ADVERTISING_PAYLOAD)
                    m_hardcode_enc_advdata[ADV_PAYLOAD_WITH_BATTERY]    = m_percentage_batt_lvl;
    #endif

  • Hi there Jimmy.

    I tried to replicate the same actions for the scan response package, but I keep getting an error.

    This is how I have changed the code:

    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 = m_enc_advdata,
                    .len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX
    
            }
    };

    Created another array:

    static uint8_t m_hardcode_enc_rspdata[BLE_GAP_ADV_SET_DATA_SIZE_MAX] =
    {
            0x02, 0x01, 0x04, //flags
            0x1B, 0xFF, 0x59,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0xAA, 0xBB, 0xCC,
    };

    And passed the pointer to the pointer the same way you do:

    m_adv_data.scan_rsp_data.p_data   = m_hardcode_enc_rspdata;
    m_adv_data.scan_rsp_data.len = 0x1F;

    When I run the code in debug, I end up getting an error.

    Any ideas?

Reply
  • Hi there Jimmy.

    I tried to replicate the same actions for the scan response package, but I keep getting an error.

    This is how I have changed the code:

    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 = m_enc_advdata,
                    .len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX
    
            }
    };

    Created another array:

    static uint8_t m_hardcode_enc_rspdata[BLE_GAP_ADV_SET_DATA_SIZE_MAX] =
    {
            0x02, 0x01, 0x04, //flags
            0x1B, 0xFF, 0x59,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0xAA, 0xBB, 0xCC,
    };

    And passed the pointer to the pointer the same way you do:

    m_adv_data.scan_rsp_data.p_data   = m_hardcode_enc_rspdata;
    m_adv_data.scan_rsp_data.len = 0x1F;

    When I run the code in debug, I end up getting an error.

    Any ideas?

Children
No Data
Related