So I'm pretty stuck working with a BLE devices and it's data. When reading from the BLE device, the data is stored in a data object. Now for this example I'm going to take the Epoch time as this (should) be an easy one to check. So the pod Bluejay saves the data, and when printing the data as follow debugPrint("Epoch Time: \(data as NSData)")
the result is this "Epoch Time: <869c0200>"
. So far so good I thought. When I copy the value 869c0200
and put it in the Mac calculator(programmer mode), do byte flip, and check it with the website epochtimeconverter I get a plausible date in 1970. Because it always resets after a dead battery to 1970. Now when I set a breakpoint and look at the values I see a couple of thing.
_bytes UnsafeMutableRawPointer? (_rawValue = 0x00000001c04364b0)
_rawValue Builtin.RawPointer 0x1c04364b0
each of them gives me a diffrent time. Is there someone who could help me, step by step how I should interprate this data en work with it the correct way?
In short:"How can I correctly read/manipulate the epochtime from my BLE device?"
Thanks in advance for the time reading.
You can't print NSData the way you are trying to print.You have to convert it to string(Byte array).
Ex:
let yourDataByte = [UInt8](advertiseData as! NSData)
let yourString = String(NSString(format:"%02X", Int(yourDataByte[0])))