Handle the BLE Event in nRF connect SDK?

hi,

I am using nRF5340 SoC in my application. I am using BLE in that application. i am beginner to nrf connect sdk so, I have few question regarding BLE implementation.  

1). In nrf sdk17.1.0,  we can  handle the ble event and advertisement event using registering callback handler function. But in nrf connect sdk 2.5.2 sdk i diden't found to handle the ble data.

ex.    BLE Event 

// Register a handler for BLE events.
    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);



static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    ret_code_t err_code = NRF_SUCCESS;

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_DISCONNECTED:
            NRF_LOG_INFO("Disconnected.");
            _connFlag = false;
           
            SF_SystemOff();
            //if(!SF_GetChargingStatus() && !GW_GetChargingStatus())
            //{
            // // LI_LedStateOn(LI_IDLE);
            //}
            BCM_NotifyTimerDisable();

            break;

        case BLE_GAP_EVT_CONNECTED:
            NRF_LOG_INFO("Connected.");
            _advFlag=false;
            SF_SystemOn();
            m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
            err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
            APP_ERROR_CHECK(err_code);

            _connFlag = true;
            if(!SF_GetChargingStatus() && !GW_GetChargingStatus())
            {
              LI_LedStateOn(LI_IDLE);
              LI_LedStateOn(LI_BLE_CONN);
            }
            break;

        case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
        {
            NRF_LOG_DEBUG("PHY update request.");
            ble_gap_phys_t const phys =
            {
                .rx_phys = BLE_GAP_PHY_AUTO,
                .tx_phys = BLE_GAP_PHY_AUTO,
            };
            err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
            APP_ERROR_CHECK(err_code);
        } break;

        case BLE_GATTC_EVT_TIMEOUT:
            // Disconnect on GATT Client timeout event.
            NRF_LOG_DEBUG("GATT Client Timeout.");
            err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gattc_evt.conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GATTS_EVT_TIMEOUT:
            // Disconnect on GATT Server timeout event.
            NRF_LOG_DEBUG("GATT Server Timeout.");
            err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gatts_evt.conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
            break;

        default:
            // No implementation needed.
            break;
    }
}

ex: For advertisement Event

static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
{
    ret_code_t err_code;

    switch (ble_adv_evt)
    {
        case BLE_ADV_EVT_FAST:
            NRF_LOG_INFO("Fast advertising.");
            _advFlag = true;
            break;

        case BLE_ADV_EVT_IDLE:
            NRF_LOG_INFO("Device advertisment off");
            break;

        default:
            break;
    }
}

static void advertising_init(void)
{
    ret_code_t             err_code;
    ble_advertising_init_t init;
    .
    .
    .
    .
    init.evt_handler = on_adv_evt;

    err_code = ble_advertising_init(&m_advertising, &init);
    APP_ERROR_CHECK(err_code);

    ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
}

i am use ble handle in NRF SDK like above.

So in nrf connect sdk is there any way to handle the advertising and ble event? or how can i handle the advertising event and ble event?

please refer me any particular example regarding BLE Event.

Thank you. 

Parents Reply
  • hi,

    Thank you for quick response.

    I modify the code as you suggest but in this case advertisement will stop after connection.

    But understand my requirement after connection advertise will not going to stop. advertisement will stop after 1 minute from disconnection happen.

    so my requirement is advertisement will stop after 1 minute from disconnection.

    Thanks and regard

    Gautam.

      

Children
Related