Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the rssi value for a bluetooth low energy device ?

I am new with android programming and trying to get rssi value form a BLE device for distance measurements.i can scan and get the name and mac address of the device but i've tried codes to get the rssi but can't get useful result,also i use the sample on the android developer site. can someone give me the right code to do so??

like image 763
alaa Avatar asked Mar 31 '15 09:03

alaa


People also ask

How is Bluetooth RSSI calculated?

Distance = 10 ^ ((Measured Power -RSSI)/(10 * N))

What is BLE RSSI?

Bluetooth Low Energy (BLE) is one of the RF-based technologies that has been utilizing Received Signal Strength Indicators (RSSI) in indoor position location systems (IPS) for decades. Its recent signal stability and propagation distance improvement inspired us to conduct this project.

How do you calculate the distance from the RSSI value of a BLE beacon?

You can calculate the distance information from RSSI value with this formula: Distance = 10^((Measured Power - Instant RSSI)/10*N). N is the constant for the environmental factor.

How is RSSI measured?

The RSSI is measured in dBm. A greater negative value (in dBm) indicates a weaker signal. Therefore, -50 dBm is better than -60 dBm. XBee module's pin 6 can be configured as an RSSI pin that outputs a PWM (pulse-width modulation) signal representing this value.


1 Answers

Two solution for this.There is different approach one can have for 4.0 and 5.0 devices to search/scan BLE devices. You did not mentioned which one you are using, hence adding both the solution below.

1) for Android 4.4 + till 5.0, you have to start LE scanning via BluetoothAdapter's startLEScan method, which gives you below callback with RSSI value. see signature of method.

onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord)

// second param above is RSSI value.

2) For android 5.0+ devices you have to start scanning by BluetoothLeScanner class's startScan method, like below

getBluetoothLeScanner().startScan

which has callback onScanResult to notify for new scanned device, you can use below code to get rssi.

public void onScanResult(int callbackType, ScanResult result) {
final int rssi = result.getRssi(); //RSSI value
like image 114
AAnkit Avatar answered Sep 20 '22 14:09

AAnkit