Skip to content

Commit 6d3cbe3

Browse files
authored
Add check on stabilisation fo weight and LBS handling (1technophile#868)
1 parent 4a17757 commit 6d3cbe3

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

main/ZgatewayBT.ino

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,10 +1247,20 @@ JsonObject& process_sensors(int offset, JsonObject& BLEdata) {
12471247
JsonObject& process_scale_v1(JsonObject& BLEdata) {
12481248
const char* servicedata = BLEdata["servicedata"].as<const char*>();
12491249

1250-
double weight = (double)value_from_hex_data(servicedata, 2, 4, true) / 200;
1251-
1252-
//Set Json value
1253-
BLEdata.set("weight", (double)weight);
1250+
if (servicedata[0] == '2') { // stabilized
1251+
double weight = 0;
1252+
if (servicedata[1] == '2') { //kg
1253+
weight = (double)value_from_hex_data(servicedata, 2, 4, true) / 200;
1254+
BLEdata.set("unit", "kg");
1255+
} else if (servicedata[1] == '3') { //lbs
1256+
weight = (double)value_from_hex_data(servicedata, 2, 4, true) / 100;
1257+
BLEdata.set("unit", "lbs");
1258+
} else { //unknown unit
1259+
BLEdata.set("unit", "unknown");
1260+
}
1261+
//Set Json value
1262+
BLEdata.set("weight", (double)weight);
1263+
}
12541264

12551265
return BLEdata;
12561266
}

0 commit comments

Comments
 (0)