I'm trying to send date information to a BLE device as part of pairing process. The BLE device documentation says that my application should set time and date to the BLE device at pairing mode, which I'm guessing is how the bond is set? (please correct me if I am wrong. Nowhere in the documentation does it say how to send encryption keys or anything of the sort).
The BLE documentation says it requires to receive 7 bytes
Name | Byte | Format | Value |
---|---|---|---|
Year | 2 | 16bit | 07DD~08CF |
Month | 1 | 8bit | 01~0C |
Day | 1 | 8bit | 01~1F |
Hours | 1 | 8bit | 00~18 |
Minutes | 1 | 8bit | 00~3B |
Second | 1 | 8bit | 00~3B |
When I use nRF connect to attempt connection with the BLE device, I see the Date UUID (0x2A08
), and when I retrieve the value, it gives me 0xDD-07-01-01-00-12-09
in Byte Array (Hex) format, or in Date: Tue, Jan 1, 2013, 00:18:09
I followed this post to be able to convert date object into byte array.
But when I do:
let date = Date()
let array = Array(date.data)
I get back:
2022-06-17 04:05:51 +0000
[0, 0, 128, 143, 26, 46, 196, 65]
I think the timezone +0000
is adding onto the byte array, but I am not sure how to remove that timezone part of the date. Even using DateFormatter to specify yyyy-MM-dd HH:mm:ss
gives me the timezone.
Also, I know very very little about bytes and all that stuff, but the array of bytes printed above doesnt look like the 8bit format that my BLE documentation requests.
Is there any way that I can better retrieve current Date (or custom set time) into 8bit byte array that I can write back to the BLE device?
Thank you