0

I have been trying to process data received from a BLE A&D Medical Thermometer (UT-201BLE-A) (Service UUID 0x1809) in my Flutter app. The characteristic (UUID 0x2A1C, Temperature Measurement) value I retrieve is this array (-Uint8ListView);

[6, 112, 1, 0, 255, 229, 7, 2, 12, 10, 56, 34, 2]

with the 6 being a flag for the data being in Celcius, and I am only really interested in the following 112, 1, 0, 255, which corresponds to the temperature (36.8).

They are in IEEE 11073 32bit float format.

I have been trying to convert this Python code I found into Dart, but am not having much luck.

I would appreciate any suggestions that could point me in the right direction. So far what I have found regarding this deal with other programming languages I am not familiar with.

CLARIFICATION - Despite a similar question being asked here, it doesn't directly provide an answer to my problem, thus I asked a new question.

ANSWER - Kindly provided by M. Kotzjan in the comments.

phuclv
  • 37,963
  • 15
  • 156
  • 475
  • What BLE thermometer are you using? What services and characteristics are you reading? Have a look at this answer on how to use the found UUID to get more informations: https://stackoverflow.com/a/66011765/7473793 – Michael Kotzjan Feb 12 '21 at 09:52
  • It is a A&D Medical Thermometer (UT-201BLE-A), and I'm looking at the characteristic UUID 0x2A1C (for Temperature Measurement). – Andwey Chupo Feb 12 '21 at 09:59
  • Maybe you can found help with this JS snippet, more close to Dart than Python : https://gist.github.com/mold/42935cb1bdda7ae9b3ec72e9d0fa8666 `getInt8` method and `bitwise operators` exist in Dart – Doubidou Feb 12 '21 at 10:03
  • @jamesdlin I tried reading through it but couldn't make sense of some parts. For example, what is the connection between the data 0xFF00016C and a value of 36.4 Celcius. – Andwey Chupo Feb 12 '21 at 10:14
  • @Doubidou Thanks for the suggestion, I am a little confused what a JS `DataView` is and what it's Dart equivalent would be. – Andwey Chupo Feb 12 '21 at 10:49
  • @AndweyChupo Hex FF = -1 in 2's complement, Hex 00016C = 364 in 2's complement. Now calculate 364 * 10^-1 and you got 36.4. In your example you need to reverse the byte order to 255, 0, 1, 112 (in Hex FF000170) and do the same calculation – Michael Kotzjan Feb 12 '21 at 10:52
  • @AndweyChupo `printFloatValue(List data, offset) { List values = data.getRange(offset, offset+4).toList(); int mantissa = values[0] | (values[1] << 8) | (values[2] << 16); int exponent = (values[3] - 255) - 1; print(mantissa * pow(10, exponent)); }` would be the equivalent in dart. Call it using your array and 1 as an offset. – Michael Kotzjan Feb 12 '21 at 12:12
  • 1
    @M.Kotzjan Thank you very much for the help! Unfortunately I lacked the knowledge about binary numbers, two's complement, etc, so the other similar question went over my head. Now I have something I can read up on. – Andwey Chupo Feb 15 '21 at 01:17

0 Answers0