Skip to content

Commit

Permalink
BLE tracker decoder (#303)
Browse files Browse the repository at this point in the history
BLE tracker decoder for
nut
iTAG
Tag-It
Tile
trackers

Update adding-decoders.md
  • Loading branch information
DigiH authored Mar 9, 2023
1 parent 874da32 commit 2fd6ff2
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 4 deletions.
9 changes: 6 additions & 3 deletions docs/participate/adding-decoders.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Each device should also have an encoded **tag** property to, at the minimum, def
</thead>
<tbody>
<tr>
<td rowspan=19>Byte[0]</td>
<td rowspan=19>Device Type > "type":</td>
<td rowspan=20>Byte[0]</td>
<td rowspan=20>Device Type > "type":</td>
<td rowspan=1>0 - Reserved</td>
</tr>
<tr>
Expand Down Expand Up @@ -102,7 +102,10 @@ Each device should also have an encoded **tag** property to, at the minimum, def
<td rowspan=1>15 - AIR - air environmental monitoring devices</td>
</tr>
<tr>
<td rowspan=1>16-254 - Reserved</td>
<td rowspan=1>16 - TRACK - bluetooth tracker</td>
</tr>
<tr>
<td rowspan=1>17-253 - Reserved</td>
</tr>
<tr>
<td rowspan=1>254 - RMAC - known random MAC address devices</td>
Expand Down
5 changes: 4 additions & 1 deletion src/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ class TheengsDecoder {
MOPEKA,
T201,
T301,
NUT,
ITAG,
TAGIT,
TILE,
IBEACON,
SERVICE_DATA,
JHT_F525,
Expand Down
5 changes: 5 additions & 0 deletions src/devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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},
Expand Down
70 changes: 70 additions & 0 deletions src/devices/tracker_json.h
Original file line number Diff line number Diff line change
@@ -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"
}
}
})"""";*/
3 changes: 3 additions & 0 deletions tests/BLE/test_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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[]{
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 2fd6ff2

Please sign in to comment.