Home > Mobile >  Unable to decode weight machine value when bluetooth weight scale in KG mode in flutter
Unable to decode weight machine value when bluetooth weight scale in KG mode in flutter

Time:06-17

My weight scale has two modes:

when the device is in-lb(pound mode) the decode output response is correct

DEVICE OUTPUT :[3, 52, 18, 224, 7, 2, 25, 3, 49, 28]

EXPECTED VALUE: 46.6lb

ACTUAL VALUE : 46.6lb

When DEVICE IS IN LB MODE the output is CORRECT using below code

double getWeight(List<int> data, index) {. return (( 0xff & data[index 1] ) << 8 | ( 0xff & data[index] ) << 0 ) / 100; }

Refer below link for the above code details: Flutter ble read weight scale characteristic value

But When the device unit is KG MODE, the decode output response is wrong

DEVICE OUTPUT :[2, 168, 12, 224, 7, 2, 25, 3, 51, 7]

EXPECTED VALUE: 46.7 lb

MY DECODED VALUE:32.4 lb

Consume please guide to decode it proper way for this issue?

CodePudding user response:

If you look for "3.244 Weight Scale Measurement" in the following document: https://www.bluetooth.com/specifications/specs/gatt-specification-supplement-6/

It says about the weight field:

This field is in kilograms with resolution 0.005 if the bit 0 of the Flag field is 0 or in pounds with a resolution of 0.01 if the bit 0 of the Flag field is 1.

So if the flag suggests you are in KG then you function is:

double getKgWeight(List<int> data, index) {
  return (( 0xff & data[index   1] ) << 8 | ( 0xff & data[index] ) << 0 ) * 0.005;
}

For lbs:

double getlbsWeight(List<int> data, index) {
  return (( 0xff & data[index   1] ) << 8 | ( 0xff & data[index] ) << 0 ) * 0.01;
}
  • Related