How to extract temperature decimal value from a Bluetooth LE (SIG) hex value

扶醉桌前 提交于 2021-02-11 13:58:57

问题


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:

  • For 36.0 celsius i got 06-68-01-00-FF-E2-07-03-0A-15-34-00-02
  • For 36.2 celsius i got 06-6A-01-00-FF-E2-07-03-0A-14-14-00-02
  • For 36.8 celsius i got 06-70-01-00-FF-E2-07-03-0A-14-1B-00-02
  • For 34.6 celsius i got 06-5A-01-00-FF-E2-07-03-0A-14-1F-00-02

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)?


回答1:


"My problem is that it's in hexadecimal format". I'm sure that you receive a byte-array, you just read or print 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, meaning Time Stamp field present, if 0 Time Stamp field not present. bit 2 = 1, meaning Temperature Type field present, if 0 Temperature Type field not present.

All other bits are not relevant, they are reserved for future use.

Bites[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

Bites3 and 4 have no meaning here. normally they are part of the 4 byte temperature float.

Bites [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).

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




回答2:


The specification for the temperature characteristic can be found here: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.temperature_measurement.xml

So basically the temperature value is a float spanning 4 bytes.




回答3:


These data come from the Bluetooth specs, depending on the service you need to use, in this case the service is the temperature. The information is written inside the xml file of the service specification. See the following link for temperature, it is from Bluetooth.com

see temperature service here

Another explanation exist in this link. See the solution in this link for details

The following link has a list of many xml files of the services used in bluetooth. I am adding it for reference. many xml services here



来源:https://stackoverflow.com/questions/54829004/how-to-extract-temperature-decimal-value-from-a-bluetooth-le-sig-hex-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!