Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RSSI to Distance Conversion
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;
}
}
@05bca054

This comment has been minimized.

Copy link

@05bca054 05bca054 commented Sep 26, 2015

Distance in meter or in feet?

@csrgxtu

This comment has been minimized.

Copy link

@csrgxtu csrgxtu commented Nov 23, 2016

it is not accurate

@cjlarsen

This comment has been minimized.

Copy link

@cjlarsen cjlarsen commented Feb 7, 2017

🥇

@bhadreshpatoliya

This comment has been minimized.

Copy link

@bhadreshpatoliya bhadreshpatoliya commented Apr 17, 2017

Thanks.

@jitendra-kr

This comment has been minimized.

Copy link

@jitendra-kr jitendra-kr commented Nov 22, 2017

Is it possible to get latitude and longitude by using RSSI without GPS?
I am working on beacon tracking application. Beacon sends data to gateway and gateway pass data to server.

@aleksey-korotkevich

This comment has been minimized.

Copy link

@aleksey-korotkevich aleksey-korotkevich commented Nov 22, 2017

@jimmy2020
Nope, rssi stand for Received signal strength indication. Basically it is just a signal strength

@totterfree

This comment has been minimized.

Copy link

@totterfree totterfree commented Mar 14, 2018

Can someone explain the need for lines 10-12?

@vishnu667

This comment has been minimized.

Copy link

@vishnu667 vishnu667 commented Mar 27, 2018

@totterfree Not sure how those values came to be but do read the answer in the stackOverflow post
https://stackoverflow.com/a/20434019/2104970

@SonUET

This comment has been minimized.

Copy link

@SonUET SonUET commented Jun 8, 2018

Not accurate, 0.89976, 7.7095 and 0.111 are average numbers

@JohanPhom

This comment has been minimized.

Copy link

@JohanPhom JohanPhom commented Jan 8, 2021

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

@JohanPhom

This comment has been minimized.

Copy link

@JohanPhom JohanPhom commented Jan 8, 2021

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