From 452233258fac3f51cb2e86ca3c457072f9644e19 Mon Sep 17 00:00:00 2001 From: Florian <1technophile@users.noreply.github.com> Date: Fri, 26 Feb 2021 15:08:13 -0600 Subject: [PATCH] Add check on stabilisation fo weight and LBS handling (#868) --- main/ZgatewayBT.ino | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index f80d712..c3bea90 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -1247,10 +1247,20 @@ JsonObject& process_sensors(int offset, JsonObject& BLEdata) { JsonObject& process_scale_v1(JsonObject& BLEdata) { const char* servicedata = BLEdata["servicedata"].as(); - double weight = (double)value_from_hex_data(servicedata, 2, 4, true) / 200; - - //Set Json value - BLEdata.set("weight", (double)weight); + if (servicedata[0] == '2') { // stabilized + double weight = 0; + if (servicedata[1] == '2') { //kg + weight = (double)value_from_hex_data(servicedata, 2, 4, true) / 200; + BLEdata.set("unit", "kg"); + } else if (servicedata[1] == '3') { //lbs + weight = (double)value_from_hex_data(servicedata, 2, 4, true) / 100; + BLEdata.set("unit", "lbs"); + } else { //unknown unit + BLEdata.set("unit", "unknown"); + } + //Set Json value + BLEdata.set("weight", (double)weight); + } return BLEdata; }