Simple question:
Is possible a central to evaluate RSSI before connecting to a peripheral?
The idea is to make central device connect and bond to a peripheral only if a determined RSSI is achieved.
Cheers
Fávero
Simple question:
Is possible a central to evaluate RSSI before connecting to a peripheral?
The idea is to make central device connect and bond to a peripheral only if a determined RSSI is achieved.
Cheers
Fávero
Complementing Anders Strand answer, when using SDK 15, things are a little different.
You can use examples\ble_central\ble_app_multilink_central as an starting point.
First you need to disable auto connect in scan_init() function:
static void scan_init(void) { ret_code_t err_code; nrf_ble_scan_init_t init_scan; memset(&init_scan, 0, sizeof(init_scan)); init_scan.connect_if_match = false; // I CHANGED init_scan.conn_cfg_tag = APP_BLE_CONN_CFG_TAG; //continues... }
Then on scan_evt_handler(scan_evt_t const * p_scan_evt) function you need to add a "case" on the "switch case" to look for
static void scan_evt_handler(scan_evt_t const * p_scan_evt) { ret_code_t err_code; switch(p_scan_evt->scan_evt_id) { case NRF_BLE_SCAN_EVT_CONNECTING_ERROR: { err_code = p_scan_evt->params.connecting_err.err_code; APP_ERROR_CHECK(err_code); } break; case NRF_BLE_SCAN_EVT_FILTER_MATCH: //CASE ADDED { int read_rssi = p_scan_evt->params.filter_match.p_adv_report->rssi; //PRINTS PEER ID OF THE CURRENT SCAN NRF_LOG_RAW_INFO("PEER ID = ") for (int i = 0; i < BLE_GAP_ADDR_LEN; i++){ NRF_LOG_RAW_INFO("%02x", p_scan_evt->params.connected.p_connected->peer_addr.addr[i]); } NRF_LOG_RAW_INFO("\r\n"); //PRINTS RSSI VALUE NRF_LOG_RAW_INFO("RSSI = %d", read_rssi); NRF_LOG_RAW_INFO("\r\n"); NRF_LOG_RAW_INFO("\r\n"); //NRF_LOG_INFO("RSSI = %d", read_rssi); break; } default: break; } }
Complementing Anders Strand answer, when using SDK 15, things are a little different.
You can use examples\ble_central\ble_app_multilink_central as an starting point.
First you need to disable auto connect in scan_init() function:
static void scan_init(void) { ret_code_t err_code; nrf_ble_scan_init_t init_scan; memset(&init_scan, 0, sizeof(init_scan)); init_scan.connect_if_match = false; // I CHANGED init_scan.conn_cfg_tag = APP_BLE_CONN_CFG_TAG; //continues... }
Then on scan_evt_handler(scan_evt_t const * p_scan_evt) function you need to add a "case" on the "switch case" to look for
static void scan_evt_handler(scan_evt_t const * p_scan_evt) { ret_code_t err_code; switch(p_scan_evt->scan_evt_id) { case NRF_BLE_SCAN_EVT_CONNECTING_ERROR: { err_code = p_scan_evt->params.connecting_err.err_code; APP_ERROR_CHECK(err_code); } break; case NRF_BLE_SCAN_EVT_FILTER_MATCH: //CASE ADDED { int read_rssi = p_scan_evt->params.filter_match.p_adv_report->rssi; //PRINTS PEER ID OF THE CURRENT SCAN NRF_LOG_RAW_INFO("PEER ID = ") for (int i = 0; i < BLE_GAP_ADDR_LEN; i++){ NRF_LOG_RAW_INFO("%02x", p_scan_evt->params.connected.p_connected->peer_addr.addr[i]); } NRF_LOG_RAW_INFO("\r\n"); //PRINTS RSSI VALUE NRF_LOG_RAW_INFO("RSSI = %d", read_rssi); NRF_LOG_RAW_INFO("\r\n"); NRF_LOG_RAW_INFO("\r\n"); //NRF_LOG_INFO("RSSI = %d", read_rssi); break; } default: break; } }