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