davidchatting / Approximate

The Approximate Library is a WiFi Arduino library for building proximate interactions between your Internet of Things and the ESP8266 or ESP32
MIT License
124 stars 17 forks source link

Approximate Distance #29

Closed DonnC closed 3 years ago

DonnC commented 3 years ago

Hello, first off, great library

I wanted to know if there is a way to get approximate distance? i understand from this section you described the approximate RSSI and their corresponding approximate distance, i believe the library uses rssi strength to determine the proximity of the other device. Does the library exposes a function to get the approximate distance?

davidchatting commented 3 years ago

Hi there - thanks for checking out the library.

You can ask a Device for its most recent RSSI value with getRSSI() - demonstrated in the FindMy example, but I don't currently have a conversion from that to distance as a function.

If you had a device in a large empty space, no walls, no people, etc - then you could probably map RSSI to distance quite successfully - but as soon as there's anything going on in the environment then things get more complicated. The way I've been thinking about this is that within a period of time the highest peak RSSI value you see might give you a good idea of how close the device is, but you are likely to see a lot of lower readings too - as things move about in the world and attenuate the signal. It also depends on the power of the radio in the device and I think sometimes that can change dynamically. All that means that it's hard to say in general terms how RSSI maps to distance.

However, if you use peak RSSI values and my threshold values as a starting guess, a function might look like this: distance_in_cm = max(0, (-13.35*rssi) - 340.0)

I would suggest collecting you own RSSI data with the hardware you'd like to use and going from there. It's much more complicated, but the CSI fingerprint that the ESP32 can generate (and the Approximate library allows you to access) might be another route.

I'll close the issue, but I'm very happy to follow-up on this thread if you have any more questions/comments.

Cheers, David