How can I get rssi before I make a connection?

purgoufr gravatar image

asked 2017-10-16 09:58:27 +0100

Hello ,

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;

case BLE_GAP_EVT_RSSI_CHANGED:                       
                        rssi_value = p_ble_evt->evt.gap_evt.params.rssi_changed.rssi;

                        else if(rssi_value<-48)


But I want to read the rssi value as in the NRFToolbox application before establishing a connection.


edit retag flag offensive close delete report spam


2 answers

Sort by » oldest newest most voted
joh2 gravatar image

answered 2017-10-16 16:51:24 +0100

purgoufr gravatar image

updated 2017-10-17 07:27:13 +0100

It seems I missread your initial question. The RSSI is present in the advertising report passed to the ble_evt_handler with the BLE_GAP_EVT_ADV_REPORT event. You can print the RSSI of the current advertising packet like this:

NRF_LOG_INFO("RSSI: %d", p_ble_evt->evt.gap_evt.params.adv_report.rssi);

You will get advertising reports whenever the cental device are scanning and detects an advertising packet. If you want to keep track of the RSSI, you can store the device info in an array and update the stored RSSI on each received advertising packet.

edit flag offensive delete publish link more


Thank you Mr. Holmefjord. I used the BLE_GAP_EVT_ADV_REPORT function to get the rssi value before, but the energy consumption is very high. Because the device was constantly scanning. Does passive scanning solve this problem? How can I do passive scanning if the answer is yes?

purgoufr ( 2017-10-17 07:32:16 +0100 )editconvert to answer

Scanning will have high current consumption, as the radio will be in RX mode much of the time. Passive scanning will not affect this much, as this is only related to if your central send scan request to the peripherals when an advertising packet is received. You can reduce the current by increasing the scan interval parameter, or decrease the scan window parameter, but note that this will limit the timeslot where your central will detect advertising packets. This might result in long delays before advertising devices are detected. You can read more about these scan parameters in this blog post.

Jørgen Holmefjord ( 2017-10-17 09:11:10 +0100 )editconvert to answer

Ok Mr. Holmefjord Thank you.

purgoufr ( 2017-10-17 09:15:54 +0100 )editconvert to answer
joh2 gravatar image

answered 2017-10-16 11:05:54 +0100


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.

Best regards,


edit flag offensive delete publish link more


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.

purgoufr ( 2017-10-16 12:22:16 +0100 )editconvert to answer

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 ...(more)

ta2 ( 2017-10-16 13:02:29 +0100 )editconvert to answer

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,
purgoufr ( 2017-10-16 14:21:14 +0100 )editconvert to answer

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.

purgoufr ( 2017-10-16 14:21:48 +0100 )editconvert to answer

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer. Do not ask a new question or reply to an answer here.

[hide preview]

User menu

    or sign up

Recent questions

Question Tools



Asked: 2017-10-16 09:58:27 +0100

Seen: 176 times

Last updated: okt. 16 '17