Reputation: 664
How to calculate the distance between two iOS devices using a wireless connection.
I figure out we can calculate using BLE
, using RSSI
number.
But the range of the device varies and the device placed in the room far away cannot be discovered.
My requirement is to calculate the distance device present in the room.
I have looked into the Multi-peer connectivity framework, but there is no such thing as the RSSI
number.
Thanks in advance.
Upvotes: 7
Views: 704
Reputation: 664
@Lance Samaria and @ Bassem Halawa here is the code using iBeacon. I was able to achieve distance proximity 85% to 90%. I have used Kalman filter to reduce background noise.
Here is the link for Kalman filter : - [https://stackoverflow.com/q/29027824/9673374][1]
I have calculated distance using RSSI value here is the code supporting that.
func calculateNewDistance(_ txCalibratedPower: Int, rssi: Int) -> Double {
if rssi == 0 {
return -1
}
let ratio = Double(exactly:rssi)!/Double(txCalibratedPower)
if ratio < 1.0 {
return pow(10.0, ratio)
}
else {
let accuracy = 0.89976 * pow(ratio, 7.7095) + 0.111
return accuracy
}
}
Let me know if this was helpful. [1]: Kalman filter for RSSI in iOS
Upvotes: 0
Reputation: 31
You can check the new NearbyInteraction https://www.reddit.com/r/iOSProgramming/comments/hfq5w8/nearbyinteraction_guide_and_github_repository/?utm_source=share&utm_medium=web2x&context=3
but will works on iphone 11 and above , bcz thes devices have the U1 chip
Upvotes: 3