Skip to content

Instantly share code, notes, and snippets.

@MickaelCruzDB
Created June 17, 2020 06:52
Show Gist options
  • Save MickaelCruzDB/3cf768bdde48ab892c21364200142d40 to your computer and use it in GitHub Desktop.
Save MickaelCruzDB/3cf768bdde48ab892c21364200142d40 to your computer and use it in GitHub Desktop.
//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