Created
December 15, 2014 05:54
-
-
Save eklimcz-zz/446b56c0cb9cfe61d575 to your computer and use it in GitHub Desktop.
RSSI to Distance Conversion
This file contains hidden or 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
function calculateDistance(rssi) { | |
var txPower = -59 //hard coded power value. Usually ranges between -59 to -65 | |
if (rssi == 0) { | |
return -1.0; | |
} | |
var ratio = rssi*1.0/txPower; | |
if (ratio < 1.0) { | |
return Math.pow(ratio,10); | |
} | |
else { | |
var distance = (0.89976)*Math.pow(ratio,7.7095) + 0.111; | |
return distance; | |
} | |
} |
Not accurate, 0.89976, 7.7095 and 0.111 are average numbers
When I tested your code on my application, I was 2 meters far from the sender and the function returned a distance of 0.0829... . The rssi was -46dB. It seems like I should change the variable txPower much under -59. If anyone has an idea for my problem
Your code says that if you receive less than -59dB, then the sender is at most 1 meter far from you. Whereas after testing on my experience -59dB represents a longer distance
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@totterfree Not sure how those values came to be but do read the answer in the stackOverflow post
https://stackoverflow.com/a/20434019/2104970