I'm developing a xamarin android app to connect to a bluetooth low energy thermometer. I can already connect and read its value. My problem is that it's in hexadecimal format and i haven't found a way to extract its value in a decimal (celsius) format.
Here's some sample readings:
From what i understand, it must be the 2º "column" above (hexadecimal values 68, 6A, 70, 5A). The values in the 10º and 11º "columns" seams to be related to measurement time (hh-mm).
How can i extract the value? Is there a generic formula i can use? Is there a way to know it's unit of measure so i can convert to celsius (if it isn't already)?
"My problem is that it's in hexadecimal format". I'm sure that you received a byte-array, you just read or printed it in hexadecimal format.
To get something useful, you have to get the relevant data from the original byte array.
06-68-01-00-FF-E2-07-03-0A-15-34-00-02
is [6,104,1,0,255,226,7,3,10,21,52,0,2]
.
The first byte (byte[0] = 6) is a bit-flag: 00000110
.
Bit 0 is the most right = 0
, meaning Temperature Measurement Value in units of Celsius. (if 1 Fahrenheit).
Bit 1 = 1
, means Time Stamp field is present. 0
if Time Stamp field not present.
Bit 2 = 1
, means Temperature Type field is present. 0
if Temperature Type field not present.
All other bits are not relevant, they are reserved for future use.
Bytes[1] (104) and [2] (1) is the temperature as FLOAT in Celsius * 10. To get the temp multiply byte[2] by 256 and add byte[1], divide total by 10. result: 1 * 256 + 104 = 360. Temperature is 36.0
Bytes3 and 4 have no meaning here. normally they are part of the 4 byte temperature float.
Bytes [5] (226) and [6] (7) is the Year as INT16: 7 * 256 + 226 = 2018.
Byte[7] (3) is the month. 0 meaning unknown, 1 = January , here 3 = March.
Byte[8] (10) is the day of the month, here 10.
Byte[10] (21) is the Hour(Number of hours past midnight), here 21.
Byte[11] (52) is the Minute, here 52.
Byte[12] (0) is the Second, here 0.
Byte[13] (2) is the Temperature Type, here Body (general). Other options for this byte are:
1 Armpit
2 Body (general)
3 Ear (usually ear lobe)
4 Finger
5 Gastro-intestinal Tract
6 Mouth
7 Rectum
8 Toe
9 Tympanum (ear drum)
10 - 255 Reserved for future use
0 Reserved for future use```