Skip to content

Instantly share code, notes, and snippets.

@massimilianochiodi
Created April 15, 2022 08:37
Show Gist options
  • Save massimilianochiodi/15fb2d2e5d130d51fdee4c4b54e3d3dc to your computer and use it in GitHub Desktop.
Save massimilianochiodi/15fb2d2e5d130d51fdee4c4b54e3d3dc to your computer and use it in GitHub Desktop.
Calculate Ble device distance with RSSI + TXPowerLevel
private static 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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment