1

I have the following hex byte data. Can someone help me reverse engineer the temperatures calculation?

ID
||
81 00 8c 00 
82 00 aa 00 
83 00 04 01 
84 00 ff 00 
85 00 21 04 

The first byte is the id! 81-84=1-4

One of the data is 14,0 C° and another one is 17,0 C°.

My tries:
- (Second Byte * 10) + (Third Byte *10/256)
- (Second Byte - 0x80) / 2
- (Second Byte / 2) - 0x80
- Second Byte * 100
- (Second Byte / 2) - 20

4

I would guess that this is raw (unencoded) data and every row is consisted of two 16 bit integers stored in little-endian order. This means that

temperature = (float)(b[3] << 8 + b[2]) / 10;

where b[2] is the third byte and b[3] is the fourth.

So using the above formula, the data would yield the following temperatures:

81 00 8c 00; #Measurement 0x0081 - 14.0
82 00 aa 00; #Measurement 0x0082 - 17.0
83 00 04 01; #Measurement 0x0083 - 26.0
84 00 ff 00; #Measurement 0x0084 - 25.5
85 00 21 04; #Measurement 0x0085 - 105.7

Update:

Here is a Python snippet which does the conversion given a string with space-separated hex values:

input = "81 00 8c 00"
byte_arr = input.split(" ")

for i in range(len(byte_arr)):
    byte_arr[i] = int(byte_arr[i], 16)

measurement_id = byte_arr[1] << 8 | byte_arr[0]
temperature = (byte_arr[3] << 8 | byte_arr[2]) / 10.0

print("Measurement: %d" % measurement_id)
print("Temperature: %.2f C°" % temperature)
  • Thanks for your answer, Anton. Sorry for my delay. Can you explain this more for me. Specially "<<" I would like to use the code in python. If I use this I get 0.0 for "81 00 8c 00". – Schack Aug 8 at 20:02
  • The << operator refers to bit-wise left shifting. I added an example how to use the formula in Python. – Anton Angelov Aug 9 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.