Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is there a way to set a RSSI parameter on Central to connect or disconnect with peripheral automatically?

Hi all:

condition:

SDK14.2

PCA10040

example: ble_app_uart_c

I have a central device ,it need to scan  RSSI value of peripheral.

If the RSSI is more than threshold,the central will connect with peripheral automatically.

If the RSSI is less than threshold, the central will disconnect with peripheral automatically.

I use below function for connect ,but I don't have a idea for disconnect

About connect ,use below function on BLE_GAP_EVT_ADV_REPORT  ,

if its RSSI over the threshold , the central will perform "sd_ble_gap_connect()" to connect with peripheral

rssi_value=p_gap_evt->params.adv_report.rssi;

if(rssi_value>220){
    if (is_uuid_present(&m_nus_uuid, p_adv_report)){

        sd_ble_gap_connect();

        ...

    }
}

static void on_ble_central_evt(ble_evt_t const * p_ble_evt)
{
    ret_code_t            err_code;
    ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_ADV_REPORT:
        {
            ble_gap_evt_adv_report_t const * p_adv_report = &p_gap_evt->params.adv_report;
            
              					
					      rssi_value=p_gap_evt->params.adv_report.rssi;
					      addr_0=p_gap_evt->params.adv_report.peer_addr.addr[0];
					      addr_1=p_gap_evt->params.adv_report.peer_addr.addr[1];
						
				
												
					  
					
			if(rssi_value>220){
                if (is_uuid_present(&m_nus_uuid, p_adv_report))
                {
                    scan_rssi=false;
									  rssi_value=255;
									
                    err_code = sd_ble_gap_connect(&p_adv_report->peer_addr,
                                              &m_scan_params,
                                              &m_connection_param,
                                              APP_BLE_CONN_CFG_TAG);

                    if (err_code == NRF_SUCCESS)
                    {
                    // scan is automatically stopped by the connect
                        err_code = bsp_indication_set(BSP_INDICATE_IDLE);
                        APP_ERROR_CHECK(err_code);
                        NRF_LOG_INFO("Connecting to target %02x%02x%02x%02x%02x%02x",
                             p_adv_report->peer_addr.addr[0],
                             p_adv_report->peer_addr.addr[1],
                             p_adv_report->peer_addr.addr[2],
                             p_adv_report->peer_addr.addr[3],
                             p_adv_report->peer_addr.addr[4],
                             p_adv_report->peer_addr.addr[5]
                             );
                    }
                 }
		    }
        }break; // BLE_GAP_EVT_ADV_REPORT

My question is,

Is there a way to set a RSSI parameter on Central to connect or disconnect with peripheral automatically?

best regards,

Joe

Parents
  • Hi,

    The softdevice do not have any inbuilt automatic feature to connect and disconnect based on RSSI value no. However the softdevice can provide RSSI values from both advertising events and also while in a connection, so the application can use the RSSI value to for instance implement such scheme based on the RSSI value. Though you should know that RSSI can vary a lot depending on line of sight, orientation of antenna, obstacles and reflections, so I am not sure how well this will work, I would at least recommend that you average or filter the RSSI values such that you don't immediately connect or disconnect based on one RSSI measurement.

    Best regards,
    Kenneth

Reply Children
No Data
Related