I know there is lot of question on stackoverflow related to my question, but I would like to know if there is any way to get the exact distance from RSSI.
I have followed this link and some other git library methods for distance calculation as well as this tutorial. But I can't get the correct solution.
This is what I'm using to measure the distance:
protected double calculateDistance(float txPower, double rssi) {
if (rssi == 0) {
return -1.0; // if we cannot determine distance, return -1.
}
double ratio = rssi * 1.0 / txPower;
if (ratio < 1.0) {
return Math.pow(ratio, 10);
} else {
double accuracy = (0.89976) * Math.pow(ratio, 7.7095) + 0.111;
return accuracy;
}
}
When I call this method I pass the standard and rssi what i'm get from my mLeScanCallBack()
private BluetoothAdapter.LeScanCallback mLeScanCallback =
new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, final int rssi, final byte[] scanRecord) {
runOnUiThread(new Runnable() {
@Override
public void run() {
BluetoothDeviceModel bluetoothDeviceModel = new BluetoothDeviceModel(device, rssi);
mLeDeviceListAdapter.addDevice(bluetoothDeviceModel, rssi, bluetoothDeviceModel.device.getAddress());
mLeDeviceListAdapter.notifyDataSetChanged();
if (mapBluetooth != null) {
mapBluetooth.put(bluetoothDeviceModel.getDevice().getAddress(), bluetoothDeviceModel);
mLeDeviceListAdapter.refresh(mapBluetooth);
}
}
});
}
};
What Problem i'm facing?
There is nothing wrong with the code above. It gives me the distance but i'm not satisfied with that because it's not the correct distance. So can anyone tell me if it is possible to get the exact distance with the above method or if there is any other way?
I am also working on the same thing. With this method you are able to calculate the distance but that distance is changing frequently. This is because RSSI value is also changing frequently.
What you need to do is to smooth out your result and for that you have to apply Kalman Filter or (linear quadratic estimation). If you want to stick with kalman filter then start from here. Beacon Tracking
Still I am looking for better implementation of Kalman Filter for my project. Alternatively, you can smooth up your RSSI value
π πππΌπ ππππ‘h = πΌ β π πππΌπ + (1 β πΌ) β π πππΌπβ1
π πππΌπ is the recent π πππΌ value and π πππΌπβ1 is the mean π πππΌ value till previous π πππΌ.
πΌ varies from 0 to 1 [consider πΌ=0.75]
Source :- RSSI Smoothing