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

Parents
  • 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

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

Reply
  • 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.

Children
No Data
Related