Created
April 15, 2022 08:37
-
-
Save massimilianochiodi/15fb2d2e5d130d51fdee4c4b54e3d3dc to your computer and use it in GitHub Desktop.
Calculate Ble device distance with RSSI + TXPowerLevel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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