Search code examples
androidencodingcharacter-encodingbluetooth-lowenergyarraybuffer

Decode BLE Temperature characteristics value to Celsius


I am using a BLE device to read temperature and get it on my system, but I am stuck on how to parse the encoded value returning from temperature characteristics value.

for eg: I am getting BmsBAP/aBwECAR8AAA== in response from the BLE device, and I am supposed to convert it to exactly 36.3 degree Celsius. some more readings are:

Characteristics value: BmsBAP/aBwECAR8AAA== Device Reading: 36.3 C

Characteristics value: BmwBAP/aBwECASEAAA== Device Reading: 36.4 C

Characteristics value: BmYBAP/aBwECAR0AAA== Device Reading: 35.8 C

BLE device used: FORA IR20 Infrared Thermometer

here is a snippet of code which I tried: https://stackblitz.com/edit/node-92jt2g?file=index.ts

So, need help to find out the correlation between the required temperature and the encoded value being sent from the device.


Solution

  • "BmYBAP/aBwECAR0AAA==" is encoded using Base64 and the hex rappresentation of decoded data is

    • 0x06 0x66 0x01 0x00 0x07 0x01 0x02 0x01 0x1D 0x00 0x00

    You're saying that it stays for "35.8°C" and usually raw data is stored without decimal, so it became "358". 358 could be rapresented as

    • 0x166

    As you can see "1", "6" and "6" is present in the initial bytes in "0x66" and "0x01" so you can read/reorder initial bytes like this:

    1. "0x06" seems always the same for all and I don't know what it could be. Maybe the measument unit ID
    2. 0x01 + 0x66 = 0x166 which is 358 = 35.8°C

    If you do same procedure for the others you will get:

    • "06 6C 01 00 07 01 02 01 21 00 00" for "36.4°C" = 0x01 + 0x6C = 0x16C = 364
    • "06 6B 01 00 07 01 02 01 1F 00 00" for "36.3°C" = 0x01 + 0x6B = 0x16B = 363