# How can I get rssi before I make a connection?

Hello ,

case BLE_GAP_EVT_CONNECTED:
APPL_LOG("Connected to target\r\n");
err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
APP_ERROR_CHECK(err_code);

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);
APP_ERROR_CHECK(err_code);

break;


Then I toggle LEDs according rssi value;

case BLE_GAP_EVT_RSSI_CHANGED:
nrf_gpio_pin_clear(LED1);
nrf_gpio_pin_clear(LED0);

nrf_gpio_pin_toggle(LED1);
nrf_gpio_pin_toggle(LED0);

break;


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

edit retag close delete

Sort by » oldest newest most voted

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.

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?

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

( 2017-10-17 09:11:10 +0100 )editconvert to answer

Ok Mr. Holmefjord Thank you.

( 2017-10-17 09:15:54 +0100 )editconvert to answer

Hi,

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,

Jørgen

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.

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

Which nRF5x device are you using?

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)

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

case BLE_GAP_EVT_ADV_REPORT:
{

{
&m_scan_params,
&m_connection_param);
}
break;
}

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

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

[hide preview]

## Recent blog posts

• ### Estudando Projetos do SDK 10 para nRF5x com Eclipse Oxygen (Portuguese)

Posted 2017-11-12 00:08:55 by Carlos Delfino
• ### Configurando o Eclipse Oxygen para Desenvolvimento com nRF5x (Portuguese)

Posted 2017-11-10 21:15:47 by Carlos Delfino
• ### How to use Git for embedded software development

Posted 2017-11-06 13:21:55 by Yaniv Nis
• ### Thingy:52 based Weather Station

Posted 2017-10-29 22:31:15 by Krzysztof Szewczyk
• ### How to build continuous integration and delivery process for embedded SW development

Posted 2017-10-03 11:01:29 by Yaniv Nis

## Recent questions

• ### IS BLE MESH SUPPORT ARDUINO PRIMO CORE?

Posted 2017-11-20 08:07:17 by rajeshkumar
• ### Nordic Bluetooth 5 (nRF52832)

Posted 2017-11-20 07:38:32 by pavan
• ### nrf5x eclipse in linux again

Posted 2017-11-20 07:18:59 by efiLabs
• ### Central Scan Continuously and Peripheral/Beacon Broadcast

Posted 2017-11-20 07:04:41 by kian79
• ### High PER at 2Mbps

Posted 2017-11-20 06:47:23 by Michael