From c82219e0c7c0c42a3e00781dfbfbd49b1a1a6410 Mon Sep 17 00:00:00 2001 From: DigiH Date: Tue, 28 Feb 2023 18:12:39 +0100 Subject: [PATCH] BLE tracker decoder BLE tracker decoder for nut iTAG Tag-It Tile trackers Update adding-decoders.md --- docs/participate/adding-decoders.md | 9 ++-- src/decoder.cpp | 5 ++- src/decoder.h | 4 ++ src/devices.h | 5 +++ src/devices/tracker_json.h | 70 +++++++++++++++++++++++++++++ tests/BLE/test_ble.cpp | 3 ++ 6 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 src/devices/tracker_json.h diff --git a/docs/participate/adding-decoders.md b/docs/participate/adding-decoders.md index 4cb93c10..a92598d5 100644 --- a/docs/participate/adding-decoders.md +++ b/docs/participate/adding-decoders.md @@ -52,8 +52,8 @@ Each device should also have an encoded **tag** property to, at the minimum, def - Byte[0] - Device Type > "type": + Byte[0] + Device Type > "type": 0 - Reserved @@ -102,7 +102,10 @@ Each device should also have an encoded **tag** property to, at the minimum, def 15 - AIR - air environmental monitoring devices - 16-254 - Reserved + 16 - TRACK - bluetooth tracker + + + 17-253 - Reserved 254 - RMAC - known random MAC address devices diff --git a/src/decoder.cpp b/src/decoder.cpp index a848245f..2c872ee1 100644 --- a/src/decoder.cpp +++ b/src/decoder.cpp @@ -471,7 +471,7 @@ int TheengsDecoder::decodeBLEJson(JsonObject& jsondata) { int success = -1; // if there is no data to decode just return - if (svc_data == nullptr && mfg_data == nullptr) { + if (svc_data == nullptr && mfg_data == nullptr && dev_name == nullptr) { DEBUG_PRINT("Invalid data\n"); return success; } @@ -549,6 +549,9 @@ int TheengsDecoder::decodeBLEJson(JsonObject& jsondata) { case 15: doc["type"] = "AIR"; // air environmental monitoring devices break; + case 16: + doc["type"] = "TRACK"; // Bluetooth tracker + break; case 254: doc["type"] = "RMAC"; // random MAC address devices break; diff --git a/src/decoder.h b/src/decoder.h index f09f437e..45aa3ef6 100644 --- a/src/decoder.h +++ b/src/decoder.h @@ -112,6 +112,10 @@ class TheengsDecoder { MOPEKA, T201, T301, + NUT, + ITAG, + TAGIT, + TILE, IBEACON, SERVICE_DATA, JHT_F525, diff --git a/src/devices.h b/src/devices.h index 5d5e923b..43c39e28 100644 --- a/src/devices.h +++ b/src/devices.h @@ -72,6 +72,7 @@ #include "devices/Mopeka_json.h" #include "devices/T201_json.h" #include "devices/T301_json.h" +#include "devices/tracker_json.h" #include "devices/iBeacon_json.h" #include "devices/iNodeEM_json.h" #include "devices/BC08_json.h" @@ -151,6 +152,10 @@ const char* _devices[][2] = { {_Mopeka_json, _Mopeka_json_props}, {_T201_json, _T201_json_props}, {_T301_json, _T301_json_props}, + {_tracker_json_nut, _tracker_json_props}, + {_tracker_json_itag, _tracker_json_props}, + {_tracker_json_tagit, _tracker_json_props}, + {_tracker_json_tile, _tracker_json_props}, {_ibeacon_json, _ibeacon_json_props}, {_ServiceData_json, _ServiceData_json_props}, {_JHT_F525_json, _JHT_F525_json_props}, diff --git a/src/devices/tracker_json.h b/src/devices/tracker_json.h new file mode 100644 index 00000000..5d139e8a --- /dev/null +++ b/src/devices/tracker_json.h @@ -0,0 +1,70 @@ +const char* _tracker_json_nut = "{\"brand\":\"nut\",\"model\":\"Smart Tracker\",\"model_id\":\"NUT\",\"tag\":\"1007\",\"condition\":[\"name\",\"index\",0,\"nut\",\"&\",\"manufacturerdata\",\"=\",8,\"&\",\"uuid\",\"index\",0,\"180a\",\"&\",\"servicedata\",\"mac@index\",8],\"properties\":{\"device\":{\"decoder\":[\"static_value\",\"nut Tracker\"]}}}"; +/*R""""( +{ + "brand":"nut", + "model":"Smart Tracker", + "model_id":"NUT", + "tag":"1007", + "condition":["name", "index", 0, "nut", "&", "manufacturerdata", "=", 8, "&", "uuid", "index", 0, "180a", "&", "servicedata", "mac@index", 8], + "properties":{ + "device":{ + "decoder":["static_value", "nut Tracker"] + } + } +})"""";*/ + +const char* _tracker_json_itag = "{\"brand\":\"iTAG\",\"model\":\"Smart Tracker\",\"model_id\":\"ITAG\",\"tag\":\"1007\",\"condition\":[\"name\",\"index\",0,\"iTAG\",\"&\",\"manufacturerdata\",\"=\",8],\"properties\":{\"device\":{\"decoder\":[\"static_value\",\"iTAG Tracker\"]}}}"; +/*R""""( +{ + "brand":"iTAG", + "model":"Smart Tracker", + "model_id":"ITAG", + "tag":"1007", + "condition":["name", "index", 0, "iTAG", "&", "manufacturerdata", "=", 8], + "properties":{ + "device":{ + "decoder":["static_value", "iTAG Tracker"] + } + } +})"""";*/ + +const char* _tracker_json_tagit = "{\"brand\":\"Tag-It\",\"model\":\"Smart Tracker\",\"model_id\":\"TAGIT\",\"tag\":\"1007\",\"condition\":[\"name\",\"index\",0,\"Tag-It\",\"&\",\"manufacturerdata\",\"=\",26,\"&\",\"manufacturerdata\",\"mac@index\",4],\"properties\":{\"device\":{\"decoder\":[\"static_value\",\"Tag-It Tracker\"]}}}"; +/*R""""( +{ + "brand":"Tag-It", + "model":"Smart Tracker", + "model_id":"TAGIT", + "tag":"1007", + "condition":["name", "index", 0, "Tag-It", "&", "manufacturerdata", "=", 26, "&", "manufacturerdata", "mac@index", 4], + "properties":{ + "device":{ + "decoder":["static_value", "Tag-It Tracker"] + } + } +})"""";*/ + +const char* _tracker_json_tile = "{\"brand\":\"Tile\",\"model\":\"Smart Tracker\",\"model_id\":\"TILE\",\"tag\":\"1007\",\"condition\":[\"name\",\"index\",0,\"Tile\",\"|\",\"uuid\",\"index\",0,\"feed\",\"|\",\"uuid\",\"index\",0,\"feec\",\"|\",\"uuid\",\"index\",0,\"fd84\"],\"properties\":{\"device\":{\"decoder\":[\"static_value\",\"Tile Tracker\"]}}}"; +/*R""""( +{ + "brand":"Tile", + "model":"Smart Tracker", + "model_id":"TILE", + "tag":"1007", + "condition":["name", "index", 0, "Tile", "|", "uuid", "index", 0, "feed", "|", "uuid", "index", 0, "feec", "|", "uuid", "index", 0, "fd84"], + "properties":{ + "device":{ + "decoder":["static_value", "Tile Tracker"] + } + } +})"""";*/ + +const char* _tracker_json_props = "{\"properties\":{\"device\":{\"unit\":\"string\",\"name\":\"tracker device\"}}}"; +/*R""""( +{ + "properties":{ + "device":{ + "unit":"string", + "name":"tracker device" + } + } +})"""";*/ diff --git a/tests/BLE/test_ble.cpp b/tests/BLE/test_ble.cpp index 315c15b5..b9f67a77 100644 --- a/tests/BLE/test_ble.cpp +++ b/tests/BLE/test_ble.cpp @@ -115,6 +115,7 @@ const char* expected_mfg[] = { "{\"brand\":\"Atomax\",\"model\":\"Skale I/II\",\"model_id\":\"SKALE\",\"type\":\"SCALE\",\"cidc\":false,\"weight\":29.6}", "{\"brand\":\"Atomax\",\"model\":\"Skale I/II\",\"model_id\":\"SKALE\",\"type\":\"SCALE\",\"cidc\":false,\"weight\":-92.8}", "{\"brand\":\"Apple\",\"model\":\"Apple Continuity\",\"model_id\":\"APPLE_CONT\",\"type\":\"RMAC\",\"device\":\"Apple device\"}", + "{\"brand\":\"iTAG\",\"model\":\"Smart Tracker\",\"model_id\":\"ITAG\",\"type\":\"TRACK\",\"cidc\":false,\"acts\":true,\"cont\":true,\"device\":\"iTAG Tracker\"}", }; const char* expected_name_uuid_mfgsvcdata[] = { @@ -391,6 +392,7 @@ const char* test_mfgdata[][3] = { {"Atomax", "Skale I/II", "ef81280100ff"}, {"Atomax", "Skale I/II", "ef8160fcffff"}, {"Apple", "Continuity", "4c0009060304c0a87b1e130c1adefc915b9ef8010401030c"}, + {"Tracker iTAG", "iTAG", "8afc23eb"}, }; TheengsDecoder::BLE_ID_NUM test_mfgdata_id_num[]{ @@ -488,6 +490,7 @@ TheengsDecoder::BLE_ID_NUM test_mfgdata_id_num[]{ TheengsDecoder::BLE_ID_NUM::SKALE, TheengsDecoder::BLE_ID_NUM::SKALE, TheengsDecoder::BLE_ID_NUM::APPLE_CONT, + TheengsDecoder::BLE_ID_NUM::ITAG, }; // uuid test input [test name] [device name] [uuid] [manufacturer data] [service data]