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

Failure to transmit scan response data package.

Dear all,

I have been struggling with updating my advertisement data package in SDK15. Using Jimmy Wongs's example (https://github.com/jimmywong2003/nrf5-modify-device-parameter-through-host/blob/modify_non_connectable_advertising/ble_app_change_advertising_example/main.c) and after modifying it accordingly, I was able to get the result I wanted out of it.

The working part is the following:

static uint8_t m_enc_advdata[BLE_GAP_ADV_SET_DATA_SIZE_MAX] =
{
        02, 0x01, 0x06, //flags
        0x11, 0xFF, 0x59,
        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
        0x00, 0x01, 0x02, 0x03,
};

static uint8_t m_enc_rspdata[BLE_GAP_ADV_SET_DATA_SIZE_MAX] =
{
        02, 0x01, 0x04, //flags
        0x11, 0xFF, 0x59,
        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
        0x00, 0x01, 0x02, 0x03,
};

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_rspdata,
                .len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX

        }
};

static void ble_stack_init(void)
{
    ret_code_t err_code;
    err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);

    // Configure the BLE stack using the default settings.
    // Fetch the start address of the application RAM.
    uint32_t ram_start = 0;
    err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
    APP_ERROR_CHECK(err_code);

    // Enable BLE stack.
    err_code = nrf_sdh_ble_enable(&ram_start);
    APP_ERROR_CHECK(err_code);
}

static void non_connectable_advertising_init(void)
{
        uint32_t err_code;
        m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
        m_adv_params.interval        = NON_CONNECTABLE_ADV_INTERVAL;
        m_adv_params.duration        = APP_ADV_DURATION;
        m_adv_data.adv_data.p_data = m_hardcode_enc_advdata;
        m_adv_data.adv_data.len    = 0x1F; // hardcode to 31 bytes
        m_adv_data.scan_rsp_data.p_data = m_hardcode_enc_rspdata;
        m_adv_data.scan_rsp_data.len    = 0;
        err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);
        APP_ERROR_CHECK(err_code);

}

int main(void)
{
        uint32_t err_code = NRF_SUCCESS;
        lfclk_config();
        rtc_config();
        
        saadc_init();
        nrf_drv_saadc_sample();
        measure_battery();

        wdt_init();
        gpio_init();
        
        power_management_init();
        ble_stack_init();

        sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
        sd_power_mode_set(NRF_POWER_MODE_LOWPWR);

        non_connectable_advertising_init();
        non_connect_advertising_start();

        printf("Advdatasize %d\n", sizeof(m_hardcode_enc_advdata));
        printf("Rspdatasize %d\n", sizeof(m_hardcode_enc_rspdata));


        printf("My_tag tag started!\n");
        // Enter main loop.
        for (;;)
        {
               NRF_WDT->RR[0] = WDT_RR_RR_Reload;
               measure_battery();
               idle_state_handle();
               NRF_WDT->RR[0] = WDT_RR_RR_Reload;
        }
}

But things go wrong when I change the length of the response package to a non-0 value. By wrong I mean that when I have the debugger connected the code jumps to app_error_handler.gcc.c (line 49) and from there to app_error_weak.c (line 100). The error occurs on  err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);

And it is NRF_ERROR_INVALID_PARAM. But I am not sure which parameter is wrong. Or how is the correct configuration for that matter.

Any help/indication would be very helpful.

Thank you very much

Related