How to get the correct temperature value from byte array

user10539558 :

I'm trying to create a BLE app where i want to catch the value of the temperature from a device. I'm using Temp Sitter device.

I have this UUID=0000ffe1-0000-1000-8000-00805f9b34fb. From here I get an array of bytes.

        // For all other profiles, writes the data formatted in HEX.
        final byte[] data = characteristic.getValue();

        if (data != null && data.length > 0) {
            final StringBuilder stringBuilder = new 
                                               StringBuilder(data.length);
            for(byte byteChar : data)
                stringBuilder.append(String.format("%02X ", byteChar));
            intent.putExtra(EXTRA_DATA, new String(data) + "\n" + 
            stringBuilder.toString());
        }

Here are some hex results: AA 06 11 00 3E 0D 00 62 --- AA 06 11 00 43 0D 00 67 --- AA 06 11 00 49 0D 00 6D

Can any one help me how to read the exact value of this array?

Codo :

After reverse-engineering the IRULU / Guangdong Biolight Meditech Temp Sitter app, it looks as if the message has this format:

            0      1      2      3      4      5      6      7
        +------+------+------+------+------+------+------+------+
        |Marker|Length|Type  |Subtyp|Low   |High  |Unused|Chksum|
        +------+------+------+------+------+------+------+------+

Example    AA     06     11     00     3E     0D     00     62 

The fields are:

  • Marker: Always 0xAA. Marker used to delinate message. The message format seems to be designed to send a stream of messages. 0xAA would indicate the start of a new message.
  • Length: The payload length, in bytes. It's the length without marker and without checksum.
  • Type: The type of the message. 0x11 seem to be temperature messages. There's also a message tpe 0x12 that seems interesting (even though I don't understand its purpose). Other message types are ignored by the app.
  • Subtype: The message subtype. Subtype 0 are temperature measurements. Subtype 1 and 2 seems to high and low warnings/indicators.
  • Low: The low byte of the temperature value.
  • High: The high byte of the temperature value.
  • Unused: This byte seems to be unsued and set to 0.
  • Checksum: The checksum of the payload. It is simply computed by adding all bytes of the payload (starting with length and ending with the unused field).

The temperature value is stored in 0.01 degree (probably degree Celsius). So to extract it, you compute:

double temperature = ((message[5] & 0xff) * 256 + (message[4] & 0xff)) * 0.01;

In the above example, the result would be 33.90 °C.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=105638&siteId=1