Continue advertising even after getting connected

Good day,

i would like to know if it is possible to continue broadcasting even if the device is already connected. i am using nrf52832 with SDK17.1

Parents Reply Children
  • Yes, you can do that. In the connected event you can do below and start the advertiser

        static ble_gap_adv_params_t m_adv_params;  
    
        // 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_data.adv_data.p_data, &m_adv_data.adv_data.len);
        APP_ERROR_CHECK(err_code);
    
        err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);
        APP_ERROR_CHECK(err_code);

    When you disconnect and get the disconnected event, you can stop the non connectable advertising and reconfigure it to be connectable and start the advertiser again as connectable.

  • i get an error in the sd_ble_gap_adv_set_configure.

    <error> app: ERROR 4 [NRF_ERROR_NO_MEM] at: 0x0002871F

Related