Created
June 17, 2020 06:52
-
-
Save MickaelCruzDB/3cf768bdde48ab892c21364200142d40 to your computer and use it in GitHub Desktop.
This file contains 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
//TxPower given by Jérôme | |
let power = 62.0 | |
// Truncate incoming RSSI | |
let incomingRSSI = Double(truncating: RSSI) | |
// Check if filter is already present for current peripheral | |
guard let filter = items[peripheral.identifier.uuidString] else { | |
// Init the KalmanFilter | |
items[peripheral.identifier.uuidString] = KalmanFilter(first: incomingRSSI) | |
return | |
} | |
// Apply filter with new RSSI | |
filter.applyFilter(for: incomingRSSI) | |
/* | |
* Compute distance using the following formula: | |
* 10 ^ ((Measured Power – RSSI)/(10 * N)) | |
*/ | |
let distance = pow(10, ((power - filter.estimatedRSSI) / 40)) | |
print("Found \"\(peripheral.identifier.uuidString)\" - RSSI: \(RSSI) - Distance is \(distance)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment