how to get Distance between wifi access point and Mobile Device

Ajay picture Ajay · Jan 30, 2015 · Viewed 9.3k times · Source

i am developing an android application which have module to search all nearest / detected wifi hotspot.

i can get all detail from searched wifi hotspot like, SSID, BSSID, capabilities, frequency, level and timestamp

with these information, i also need Distance of wifi ( The distance between wifi accesspoint and Mobile Device )

i am using below lines to get Distance.

double exp = (27.55 - (20 * Math.log10(freqInMHz)) + Math.abs(levelInDb)) / 20.0;
double distanceM = Math.pow(10.0, exp);

this will return distance in meter.

i got these code by reserch on google from many pages.

but i think i am going wrong, this code is returning wrong distance. i also tried a lot on google search but not getting accurate output.

Please help me. how can i get Distance between Wifi AP and Mobile device?

Answer

datenwolf picture datenwolf · Jan 30, 2015

This code:

double exp = (27.55 - (20 * Math.log10(freqInMHz)) + Math.abs(levelInDb)) / 20.0; double distanceM = Math.pow(10.0, exp);

Works under the assumption of free space path attenuation between two isotropic antennas and the AP transmitting at a power of 20dBm (and the math is not even correct; the frequency dependence of free space path loss is different; not that is matters for the bands of W-LAN, uses, the correction is in the 27.55).

In reality you're dealing with anisotropic antennas, obstacles in your path, diffraction effects and the AP varying it's power output to save energy if no high bandwidth is required.

Or in other words: It's totally impractical to obtain a reliable distance figure just looking at the received power. It can give you a ballpark, order of magnitude, but not something that's remotely accurate. This is just basic physics.

The only reliable way of measuring distance is time-of-flight. For this you have to measure the roundtrip time between the device and the access point. Since we're dealing with the speed of light and distances in the order of meters up to 100m (top), this means measuring nanoseconds. Can be done but requires some work. See the link SatelliteSD gave you (it's in German but the diagrams and keywords should be understandable).