From 04c103c381511a68d7e8cff250015ae70996bee4 Mon Sep 17 00:00:00 2001 From: DigiH Date: Tue, 22 Feb 2022 02:16:57 +0100 Subject: [PATCH] Update iBeacon_json.h (#75) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Optimised iBeacon decoder • Condensed the power and volt properties with multiple conditions • renamed battery property to volt to bring in line with other voltage --- docs/devices/iBeacon.md | 2 +- src/devices/iBeacon_json.h | 71 +++++--------------------------------- tests/BLE/test_ble.cpp | 2 +- 3 files changed, 11 insertions(+), 64 deletions(-) diff --git a/docs/devices/iBeacon.md b/docs/devices/iBeacon.md index f547794d..26c1c63c 100644 --- a/docs/devices/iBeacon.md +++ b/docs/devices/iBeacon.md @@ -8,5 +8,5 @@ |Communication|BLE broadcast| |Frequency|2.4Ghz| |Power source|Sensor dependent| -|Exchanged data|mfid, uuid, minor, major, power/battery| +|Exchanged data|mfid, uuid, minor, major, power/voltage| |Encrypted|No| diff --git a/src/devices/iBeacon_json.h b/src/devices/iBeacon_json.h index 7ed638d7..f3a97899 100644 --- a/src/devices/iBeacon_json.h +++ b/src/devices/iBeacon_json.h @@ -1,4 +1,4 @@ -const char* _ibeacon_json = "{\"brand\":\"GENERIC\",\"model\":\"IBEACON\",\"model_id\":\"IBEACON\",\"condition\":[\"manufacturerdata\",\"=\",50,\"index\",0,\"4c00\"],\"properties\":{\"mfid\":{\"decoder\":[\"string_from_hex_data\",\"manufacturerdata\",0,4]},\"uuid\":{\"decoder\":[\"string_from_hex_data\",\"manufacturerdata\",8,32]},\"major\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",40,4,false]},\"minor\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",44,4,false]},\"power\":{\"condition\":[\"manufacturerdata\",48,\"8\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",48,2,false]},\"_power\":{\"condition\":[\"manufacturerdata\",48,\"9\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",48,2,false]},\"__power\":{\"condition\":[\"manufacturerdata\",48,\"a\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",48,2,false]},\"___power\":{\"condition\":[\"manufacturerdata\",48,\"b\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",48,2,false]},\"____power\":{\"condition\":[\"manufacturerdata\",48,\"c\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",48,2,false]},\"_____power\":{\"condition\":[\"manufacturerdata\",48,\"d\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",48,2,false]},\"______power\":{\"condition\":[\"manufacturerdata\",48,\"e\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",48,2,false]},\"_______power\":{\"condition\":[\"manufacturerdata\",48,\"f\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",48,2,false]},\"battery\":{\"condition\":[\"manufacturerdata\",48,\"0\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",48,2,false],\"post_proc\":[\"/\",10]},\"_battery\":{\"condition\":[\"manufacturerdata\",48,\"1\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",48,2,false],\"post_proc\":[\"/\",10]},\"__battery\":{\"condition\":[\"manufacturerdata\",48,\"2\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",48,2,false],\"post_proc\":[\"/\",10]},\"___battery\":{\"condition\":[\"manufacturerdata\",48,\"3\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",48,2,false],\"post_proc\":[\"/\",10]},\"____battery\":{\"condition\":[\"manufacturerdata\",48,\"4\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",48,2,false],\"post_proc\":[\"/\",10]},\"_____battery\":{\"condition\":[\"manufacturerdata\",48,\"5\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",48,2,false],\"post_proc\":[\"/\",10]}}}"; +const char* _ibeacon_json = "{\"brand\":\"GENERIC\",\"model\":\"IBEACON\",\"model_id\":\"IBEACON\",\"condition\":[\"manufacturerdata\",\"=\",50,\"index\",0,\"4c00\"],\"properties\":{\"mfid\":{\"decoder\":[\"string_from_hex_data\",\"manufacturerdata\",0,4]},\"uuid\":{\"decoder\":[\"string_from_hex_data\",\"manufacturerdata\",8,32]},\"major\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",40,4,false]},\"minor\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",44,4,false]},\"power\":{\"condition\":[\"manufacturerdata\",48,\"8\",\"|\",\"manufacturerdata\",48,\"9\",\"|\",\"manufacturerdata\",48,\"a\",\"|\",\"manufacturerdata\",48,\"b\",\"|\",\"manufacturerdata\",48,\"c\",\"|\",\"manufacturerdata\",48,\"d\",\"|\",\"manufacturerdata\",48,\"e\",\"|\",\"manufacturerdata\",48,\"f\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",48,2,false]},\"volt\":{\"condition\":[\"manufacturerdata\",48,\"0\",\"|\",\"manufacturerdata\",48,\"1\",\"|\",\"manufacturerdata\",48,\"2\",\"|\",\"manufacturerdata\",48,\"3\",\"|\",\"manufacturerdata\",48,\"4\",\"|\",\"manufacturerdata\",48,\"5\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",48,2,false],\"post_proc\":[\"/\",10]}}}"; /*R""""( { @@ -20,71 +20,18 @@ const char* _ibeacon_json = "{\"brand\":\"GENERIC\",\"model\":\"IBEACON\",\"mode "decoder":["value_from_hex_data", "manufacturerdata", 44, 4, false] }, "power":{ - "condition":["manufacturerdata", 48, "8"], + "condition":["manufacturerdata", 48, "8", "|", "manufacturerdata", 48, "9", "|", "manufacturerdata", 48, "a", "|", "manufacturerdata", 48, "b", "|", "manufacturerdata", 48, "c", "|", "manufacturerdata", 48, "d", "|", "manufacturerdata", 48, "e", "|", "manufacturerdata", 48, "f"], "decoder":["value_from_hex_data","manufacturerdata", 48, 2, false] }, - "_power":{ - "condition":["manufacturerdata", 48, "9"], - "decoder":["value_from_hex_data","manufacturerdata", 48, 2, false] - }, - "__power":{ - "condition":["manufacturerdata", 48, "a"], - "decoder":["value_from_hex_data","manufacturerdata", 48, 2, false] - }, - "___power":{ - "condition":["manufacturerdata", 48, "b"], - "decoder":["value_from_hex_data","manufacturerdata", 48, 2, false] - }, - "____power":{ - "condition":["manufacturerdata", 48, "c"], - "decoder":["value_from_hex_data","manufacturerdata", 48, 2, false] - }, - "_____power":{ - "condition":["manufacturerdata", 48, "d"], - "decoder":["value_from_hex_data","manufacturerdata", 48, 2, false] - }, - "______power":{ - "condition":["manufacturerdata", 48, "e"], - "decoder":["value_from_hex_data","manufacturerdata", 48, 2, false] - }, - "_______power":{ - "condition":["manufacturerdata", 48, "f"], - "decoder":["value_from_hex_data","manufacturerdata", 48, 2, false] - }, - "battery":{ - "condition":["manufacturerdata", 48, "0"], - "decoder":["value_from_hex_data","manufacturerdata", 48, 2, false], - "post_proc":["/", 10] - }, - "_battery":{ - "condition":["manufacturerdata", 48, "1"], - "decoder":["value_from_hex_data","manufacturerdata", 48, 2, false], - "post_proc":["/", 10] - }, - "__battery":{ - "condition":["manufacturerdata", 48, "2"], - "decoder":["value_from_hex_data","manufacturerdata", 48, 2, false], - "post_proc":["/", 10] - }, - "___battery":{ - "condition":["manufacturerdata", 48, "3"], - "decoder":["value_from_hex_data","manufacturerdata", 48, 2, false], - "post_proc":["/", 10] - }, - "____battery":{ - "condition":["manufacturerdata", 48, "4"], - "decoder":["value_from_hex_data","manufacturerdata", 48, 2, false], - "post_proc":["/", 10] - }, - "_____battery":{ - "condition":["manufacturerdata", 48, "5"], + "volt":{ + "condition":["manufacturerdata", 48, "0", "|", "manufacturerdata", 48, "1", "|", "manufacturerdata", 48, "2", "|", "manufacturerdata", 48, "3", "|", "manufacturerdata", 48, "4", "|", "manufacturerdata", 48, "5"], "decoder":["value_from_hex_data","manufacturerdata", 48, 2, false], "post_proc":["/", 10] } } })"""";*/ -const char* _ibeacon_json_props = "{\"properties\":{\"mfid\":{\"unit\":\"hex\",\"name\":\"manufacturer id\"},\"uuid\":{\"unit\":\"hex\",\"name\":\"service uuid\"},\"major\":{\"unit\":\"hex\",\"name\":\"major value\"},\"minor\":{\"unit\":\"hex\",\"name\":\"minor value\"},\"power\":{\"unit\":\"int\",\"name\":\"tx power\"},\"battery\":{\"unit\":\"Volt\",\"name\":\"battery\"}}}"; +const char* _ibeacon_json_props = "{\"properties\":{\"mfid\":{\"unit\":\"hex\",\"name\":\"manufacturer id\"},\"uuid\":{\"unit\":\"hex\",\"name\":\"service uuid\"},\"major\":{\"unit\":\"hex\",\"name\":\"major value\"},\"minor\":{\"unit\":\"hex\",\"name\":\"minor value\"},\"power\":{\"unit\":\"int\",\"name\":\"tx power\"},\"volt\":{\"unit\":\"V\",\"name\":\"voltage\"}}}"; /*R""""( { "properties":{ @@ -107,10 +54,10 @@ const char* _ibeacon_json_props = "{\"properties\":{\"mfid\":{\"unit\":\"hex\",\ "power":{ "unit":"int", "name":"tx power" - }. - "battery":{ - "unit":"Volt", - "name":"battery" + }, + "volt":{ + "unit":"V", + "name":"voltage" } } })"""";*/ diff --git a/tests/BLE/test_ble.cpp b/tests/BLE/test_ble.cpp index 90e53410..82298fa5 100644 --- a/tests/BLE/test_ble.cpp +++ b/tests/BLE/test_ble.cpp @@ -43,7 +43,7 @@ const char* expected_mfg[] = { "{\"brand\":\"Inkbird\",\"model\":\"TH Sensor\",\"model_id\":\"IBS-TH1\",\"tempc\":26.62,\"tempf\":79.916,\"hum\":53.79,\"batt\":89}", "{\"brand\":\"GENERIC\",\"model\":\"TPMS\",\"model_id\":\"TPMS\",\"count\":1,\"pres\":222.708,\"tempc\":31.96,\"tempf\":89.528,\"batt\":51,\"alarm\":false}", "{\"brand\":\"GENERIC\",\"model\":\"IBEACON\",\"model_id\":\"IBEACON\",\"mfid\":\"4c00\",\"uuid\":\"426c7565436861726d426561636f6e73\",\"major\":3838,\"minor\":4949,\"power\":-59}", - "{\"brand\":\"GENERIC\",\"model\":\"IBEACON\",\"model_id\":\"IBEACON\",\"mfid\":\"4c00\",\"uuid\":\"fda50693a4e24fb1afcfc6eb07647825\",\"major\":1,\"minor\":2,\"battery\":2.6}", + "{\"brand\":\"GENERIC\",\"model\":\"IBEACON\",\"model_id\":\"IBEACON\",\"mfid\":\"4c00\",\"uuid\":\"fda50693a4e24fb1afcfc6eb07647825\",\"major\":1,\"minor\":2,\"volt\":2.6}", "{\"brand\":\"SensorBlue\",\"model\":\"WS02\",\"model_id\":\"WS02\",\"tempc\":31.3125,\"tempf\":88.3625,\"hum\":70.75,\"volt\":3.160}", "{\"brand\":\"SensorBlue\",\"model\":\"WS08\",\"model_id\":\"WS08\",\"tempc\":31.3125,\"tempf\":88.3625,\"hum\":70.75,\"volt\":3.160}", "{\"brand\":\"Govee\",\"model\":\"Smart Thermo Hygrometer\",\"model_id\":\"H5075\",\"tempc\":26.8,\"tempf\":80.24,\"hum\":52.6,\"batt\":100}",