This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How can I get rssi before I make a connection?

Hello ,

I can read the rssi value after the connection is established.

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);	

			sd_ble_gap_rssi_start(p_ble_evt->evt.gap_evt.conn_handle, 0 , 0);

            break;

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;
						nrf_gpio_pin_clear(LED1);
						nrf_gpio_pin_clear(LED0);
				
						if(rssi_value<-64)
							nrf_gpio_pin_toggle(LED1);
						else if(rssi_value<-48)
							nrf_gpio_pin_toggle(LED0);
						
					break;

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

nrf_rssi.jpg

  • 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

  • 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

    1. Tell the SoftDevice in the Central to listen for advertisements from the desired device.
    2. When you see an advertisement from the desired Peripheral, check the RSSI value that the Controller computed while receiving the advertisement.
    3. Decide is you want to connect to the device based on the RSSI.
    4. If you want to connect to that device, tell your local (Central) SoftDevice to create a connection.

    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.

    case BLE_GAP_EVT_ADV_REPORT:
            {
                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,
                                                  &m_scan_params,
                                                  &m_connection_param);                    
                }
                break;
            }
    
  • 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.

Related