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

How to add on_adv_evt in ble_app_beacon example? SDK16

Hi, i am trying to add on_adv_evt in ble_app_beacon example. I modified sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params) to sd_ble_gap_adv_set_configure(&on_adv_evt, &m_adv_data, &m_adv_params) but it is throwing fatal error and system reset. what could be the issue?

is there any way to capture advertisement timeout using event handler?

static void advertising_init(void)
{
    uint32_t      err_code;
    ble_advdata_t advdata;
    uint8_t       flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;

    ble_advdata_manuf_data_t manuf_specific_data;

    manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER;
    manuf_specific_data.data.p_data = "test";//(uint8_t *) m_beacon_info;
    manuf_specific_data.data.size   = 4;//APP_BEACON_INFO_LENGTH;

    // Build and set advertising data.
    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        = 200;       // Never time out.

    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(&on_adv_evt, &m_adv_data, &m_adv_params);
    APP_ERROR_CHECK(err_code);
}

static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
{
    uint32_t err_code;

    switch (ble_adv_evt)
    {
        case BLE_ADV_EVT_IDLE:
            //sleep_mode_enter();
            NRF_LOG_INFO("ADV_TIMEOUT");
            break;
        default:
            break;
    }
}

Related