Proximity indicator using RSSI with automatic role switching in QN9080

Showing results for 
Search instead for 
Did you mean: 

Proximity indicator using RSSI with automatic role switching in QN9080

No ratings

Proximity indicator using RSSI with automatic role switching in QN9080


The goal of this example is to demonstrate automatic role switching between Central and Peripheral of BLE QN9080 SIP and indicate the proximity of another BLE module using RSSI value.

The automatic Role Switching feature can be used for continuously scan the presence of other BLE device and also to advertise so that other BLE device can scan it. The use case is to maintain social distancing and trigger a warning if the two devices are closer than a threshold distance.

RSSI stands for Received Signal Strength Indicator which shows the power of received radio signal.

Bare metal ‘Wireless_UART’ example is used from ‘SDK_2.x_QN908xCDK’ version 2.2.2

Timer Configuration

As the device needs to switch its role after every particular time interval, so a timer is required to be initialized as it can be seen in below screenshot.


Next step is to allocate Timer ID to the declared variable and start the timer. In this case, the timer shall go to callback function after the time(seconds) defined by the macro 'gSwitchTime'. This is done in 'BleApp_Config' function.



After the specified time interval, timer stops and enters the callback function where switching of roles takes place. The main point that needs to be highlighted here is that while going into scanning mode, advertising mode should be stopped and vice versa.


In advertising, the LED will be turned off. In scanning, the LED glows based on the RSSI.

Central Configuration

While in Central mode, device scans the presence of other bluetooth devices. Here, we need to check the RSSI value of received signals from those devices.

There is a register available in QN9080 where the RSSI can be read after a received signal. RSSI is always negative, so the register stores the 2's compliment of the actual value. Below formula can be used to get the actual value of RSSI:-

Actual RSSI = NOT(RSSI) + 1;

This formula will give the positive value which is inversely proportional to Signal strength.


In the callback function of scanning 'BleApp_ScanningCallback', filtering is applied and following decisions are taken based on filtered value:-

  • Red LED will glow if the filtered value is lesser than a threshold value.
  • Green LED will glow if the filtered value is greater than a threshold value.
  • Hysteresis of 6 counts is taken to nullify the effect of fluctuation.

As there is no need to make connections with the available devices, so the function requesting to make connection with the scanned device will be deleted.


Peripheral Configuration

Advertising interval can be changed as per requirement by making changes in the following macros:-


To advertise at a fixed interval, value of minimum and maximum interval should be same.


Test Setup

  • Flash the code in two BLE EVK's.
  • Power ON the EVK's.
  • Red LED blinks if the EVK's are closer than a certain distance.
  • Green LED blinks if the distance between the EVK's is greater than a threshold value.
  • During blinking, When the LED is off, it means that the EVK is in advertising mode and when LED is ON(Red/Green), it means that EVK is in scanning mode.

Note:- RSSI varies with environment, surrounding etc., so the threshold value of distance may vary with variation in testing condition.

Demo code is attached for out of the box testing.

Labels (2)
Version history
Revision #:
2 of 2
Last update:
‎10-26-2020 03:54 PM
Updated by: