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

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

Children
Related