Skip to content

Commit

Permalink
Update iBeacon_json.h (#75)
Browse files Browse the repository at this point in the history
Optimised iBeacon decoder

• Condensed the power and volt properties with multiple conditions
• renamed battery property to volt to bring in line with other voltage
  • Loading branch information
DigiH authored Feb 22, 2022
1 parent 0f31a2b commit 04c103c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 64 deletions.
2 changes: 1 addition & 1 deletion docs/devices/iBeacon.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
71 changes: 9 additions & 62 deletions src/devices/iBeacon_json.h
Original file line number Diff line number Diff line change
@@ -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""""(
{
Expand All @@ -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":{
Expand All @@ -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"
}
}
})"""";*/
2 changes: 1 addition & 1 deletion tests/BLE/test_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down

0 comments on commit 04c103c

Please sign in to comment.