I can read the rssi value after the connection is established.
APPL_LOG("Connected to target\r\n");
err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
m_ble_nus_c.conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
// start discovery of services. The NUS Client waits for a discovery result
err_code = ble_db_discovery_start(&m_ble_db_discovery, p_ble_evt->evt.gap_evt.conn_handle);
sd_ble_gap_rssi_start(p_ble_evt->evt.gap_evt.conn_handle, 0 , 0);
Then I toggle LEDs according rssi value;
rssi_value = p_ble_evt->evt.gap_evt.params.rssi_changed.rssi;
But I want to read the rssi value as in the NRFToolbox application before establishing a connection.
The exact RSSI value is not shown in the scanner in nRF Toolbox, but the RSSI is calculated into percentage and a representative image is used to indicate the strength. You can modify the code of the app to show the RSSI value instead of, or in addition to, the image.
Firstly, thank you for your information. I do not fully understand the codes, but I work on it. The point I try to reach is actually a very common example. The keys of the newly produced cars have the keylessgo feature, and the car opens automatically when the key approaches. So I think that they make use of rssi measurement. In order to be able to evolve faster, I want to learn how to generate a rssi percentage or a number or image(as you said) with c code instead of Android? (IIf such a study had been done before.) As I said, I am examining the Toolbox example, but if there is an example written in C code, it will speed me up a lot.
Which nRF5x device are you using?
I see a BLE_GAP_EVT_ADV_REPORT event in the documentation for the S132 SoftDevice (nRF52). That event contains the RSSI for the advertisement.
I could have sworn that the capability to receive Advertising packets is also in the nRF51 SoftDevices but I'm not seeing it at the moment. I can look for it later today (Monday) if needed.
You may know this, but the connection sequence goes something like this:
o) The Central instructs it's radio (Bluetooth Controller) to connect to a particular device;
o) The Peripheral is sending out "I am connectable" advertising packets that identity the device;
o) When the Controller in the Central sees the connectable advertisement from the Peripheral, it immediately responds with a Connection Request packet which kicks off the connection sequence.
I'd need to check whether or not you get the BLE_GAP_EVT_ADV_REPORT just before the BLE_GAP_CONNECTED event.
My suspicion is that what you are wanting to do is
Be aware that some devices are setup to advertise using a particular power level, and then use a different power level during connection. Also make sure that you have some knowledge about when RSSI values are useful and when they are not.
I am working on both nrf51 (s130) and nrf52 (s132). Also I use BLE_GAP_EVT_ADV_REPORT and BLE_GaP_EVT_CONNECTED.
const ble_gap_evt_adv_report_t *p_adv_report = &p_gap_evt->params.adv_report;
if (is_uuid_present(&m_nus_uuid, p_adv_report))
err_code = sd_ble_gap_connect(&p_adv_report->peer_addr,
I tried the sd_ble_gap_rssi_start(p_ble_evt->evt.gap_evt.conn_handle, 0 , 0); function in the BLE_GAP_EVT_ADV_REPORT. But It did not work. Briefly,I did not get rssi_value continuously until I connected.
According to nordic website BLE_GAP_EVT_ADV_REPORT contains rssi value. But how can I use this data (like in the NrFToolbox application) consistently? The event chain you're describing is definitely what I want to do.