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.

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

Reply Children
No Data
Related