I am working on an application that needs to get details of another Bluetooth device when it starts scanning the nearby devices. I have managed to get a few and I am stuck at few values that I am not receiving.
Values which are needed. 1. UUID 2. rssi 3. txpower 4. Detected Device Name 5. data 6. distance 7. time 8. mac address
Out of which I have managed to get UUID, rssi, Detected Device Name and time.
I am not able to figure out how to get txpower, data, distance and mac address.
Data should be in string format.
Below are my code and output.
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
let rssi = RSSI.stringValue
print("UUID:",uuid)
print("Device Name:",peripheral.name!)
print("rssi:",rssi)
print("Ad Data:", advertisementData)
print("time:", advertisementData["kCBAdvDataTimestamp"]!)
print("peripheral:", peripheral)
if let power = advertisementData["kCBAdvDataTxPowerLevel"] as? Double{
print("power:", power)
print("Distance is ", pow(10, ((power - Double(truncating: RSSI))/20)))
}
OUTPUT
UUID: A863C72A-DCB7-43DB-9431-5F0107CB3474
Device Name: iPhone 7
rssi: -12
Ad Data: ["kCBAdvDataTimestamp": 610053944.490985, "kCBAdvDataIsConnectable": 1]
time: 610053944.490985
peripheral: <CBPeripheral: 0x2808d0780, identifier = 9511F67B-9903-7D50-467A-BAAF4ECA1479, name = iPhone 7, state = disconnected>
Please help me get this data, I have searched the internet but didn't find any relevant answer. Hence posting it here
TIA