Skip to content

Commit

Permalink
MikroTik TG-BT5-IN/-OUT Decoder (#596)
Browse files Browse the repository at this point in the history
MikroTik TG-BT5-IN/-OUT initial Decoder
  • Loading branch information
DigiH authored Jan 1, 2025
1 parent 5d0eaf9 commit 50f9ab2
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/devices/Mikrotik.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# MikroTik TG-BT5-IN & TG-BT5-OUT

|Model Id|[TG-BT5](https://github.com/theengs/decoder/blob/development/src/devices/Mikrotik_json.h)|
|-|-|
|Brand|MikroTik|
|Model|TG-BT5-IN/-OUT|
|Short Description|Indoor & Outdoor temperature and acceleration sensors|
|Communication|BLE broadcast|
|Frequency|2.4Ghz|
|Power Source|built-in non-replaceable battery|
|Exchanged Data|temperature, acceleration x/y/z-axis, uptime, battery|
|Encrypted|No - Currently only unencrypted devices are supported|
|Device Tracker|✅|
1 change: 1 addition & 0 deletions src/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class TheengsDecoder {
NODONNIU,
MOKOBEACON,
MOKOBEACONXPRO,
TGBT5,
INODEEM,
RUUVITAG_RAWV1,
RUUVITAG_RAWV2,
Expand Down
2 changes: 2 additions & 0 deletions src/devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "devices/XMTZC05HMKG_json.h"
#include "devices/XMTZC05HMLB_json.h"
#include "devices/Mokobeacon_json.h"
#include "devices/Mikrotik_json.h"
#include "devices/RDL52832_json.h"
#include "devices/RuuviTag_RAWv1_json.h"
#include "devices/RuuviTag_RAWv2_json.h"
Expand Down Expand Up @@ -171,6 +172,7 @@ const char* _devices[][2] = {
{_NODONNIU_json, _NODONNIU_json_props},
{_Mokobeacon_json, _Mokobeacon_json_props},
{_MBXPRO_json, _MBXPRO_json_props},
{_Mikrotik_json, _Mikrotik_json_props},
{_iNodeEM_json, _iNodeEM_json_props},
{_RuuviTag_RAWv1_json, _RuuviTag_RAWv1_json_props},
{_RuuviTag_RAWv2_json, _RuuviTag_RAWv2_json_props},
Expand Down
107 changes: 107 additions & 0 deletions src/devices/Mikrotik_json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
const char* _Mikrotik_json = "{\"brand\":\"MikroTik\",\"model\":\"TG-BT5-IN/-OUT\",\"model_id\":\"TG-BT5\",\"tag\":\"0708\",\"condition\":[\"manufacturerdata\",\"=\",40,\"index\",0,\"4f090100\"],\"properties\":{\"tempc\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",24,4,true,true],\"post_proc\":[\"/\",256]},\"accx\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",12,4,true,true],\"post_proc\":[\"/\",256]},\"accy\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",16,4,true,true],\"post_proc\":[\"/\",256]},\"accz\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",20,4,true,true],\"post_proc\":[\"/\",256]},\"flag_reed\":{\"decoder\":[\"bit_static_value\",\"manufacturerdata\",37,0,false,true]},\"flag_tilt\":{\"decoder\":[\"bit_static_value\",\"manufacturerdata\",37,1,false,true]},\"flag_fall\":{\"decoder\":[\"bit_static_value\",\"manufacturerdata\",37,2,false,true]},\"flag_impact_x\":{\"decoder\":[\"bit_static_value\",\"manufacturerdata\",37,3,false,true]},\"flag_impact_y\":{\"decoder\":[\"bit_static_value\",\"manufacturerdata\",36,0,false,true]},\"flag_impact_z\":{\"decoder\":[\"bit_static_value\",\"manufacturerdata\",36,1,false,true]},\"uptime\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",28,8,true,false]},\"batt\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",38,2,false,false],\"post_proc\":[\"&\",127]}}}";
/*R""""(
{
"brand":"MikroTik",
"model":"TG-BT5-IN/-OUT",
"model_id":"TG-BT5",
"tag":"0708",
"condition":["manufacturerdata", "=", 40, "index", 0, "4f090100"],
"properties":{
"tempc":{
"decoder":["value_from_hex_data", "manufacturerdata", 24, 4, true, true],
"post_proc":["/", 256]
},
"accx":{
"decoder":["value_from_hex_data", "manufacturerdata", 12, 4, true, true],
"post_proc":["/", 256]
},
"accy":{
"decoder":["value_from_hex_data", "manufacturerdata", 16, 4, true, true],
"post_proc":["/", 256]
},
"accz":{
"decoder":["value_from_hex_data", "manufacturerdata", 20, 4, true, true],
"post_proc":["/", 256]
},
"flag_reed":{
"decoder":["bit_static_value", "manufacturerdata", 37, 0, false, true]
},
"flag_tilt":{
"decoder":["bit_static_value", "manufacturerdata", 37, 1, false, true]
},
"flag_fall":{
"decoder":["bit_static_value", "manufacturerdata", 37, 2, false, true]
},
"flag_impact_x":{
"decoder":["bit_static_value", "manufacturerdata", 37, 3, false, true]
},
"flag_impact_y":{
"decoder":["bit_static_value", "manufacturerdata", 36, 0, false, true]
},
"flag_impact_z":{
"decoder":["bit_static_value", "manufacturerdata", 36, 1, false, true]
},
"uptime":{
"decoder":["value_from_hex_data", "manufacturerdata", 28, 8, true, false]
},
"batt":{
"decoder":["value_from_hex_data", "manufacturerdata", 38, 2, false, false],
"post_proc":["&", 127]
}
}
})"""";*/

const char* _Mikrotik_json_props = "{\"properties\":{\"tempc\":{\"unit\":\"°C\",\"name\":\"temperature\"},\"accx\":{\"unit\":\"m/s²\",\"name\":\"acceleration x\"},\"accy\":{\"unit\":\"m/s²\",\"name\":\"acceleration y\"},\"accz\":{\"unit\":\"m/s²\",\"name\":\"acceleration z\"},\"flag_reed\":{\"unit\":\"status\",\"name\":\"flag reed switch\"},\"flag_tilt\":{\"unit\":\"status\",\"name\":\"flag tilting\"},\"flag_fall\":{\"unit\":\"status\",\"name\":\"flag free fall\"},\"flag_impact_x\":{\"unit\":\"status\",\"name\":\"flag impact x-axis\"},\"flag_impact_y\":{\"unit\":\"status\",\"name\":\"flag impact y-axis\"},\"flag_impact_z\":{\"unit\":\"status\",\"name\":\"flag impact z-axis\"},\"uptime\":{\"unit\":\"s\",\"name\":\"duration\"},\"batt\":{\"unit\":\"%\",\"name\":\"battery\"}}}";
/*R""""(
{
"properties":{
"tempc":{
"unit":"°C",
"name":"temperature"
},
"accx":{
"unit":"m/s²",
"name":"acceleration x"
},
"accy":{
"unit":"m/s²",
"name":"acceleration y"
},
"accz":{
"unit":"m/s²",
"name":"acceleration z"
},
"flag_reed":{
"unit":"status",
"name":"flag reed switch"
},
"flag_tilt":{
"unit":"status",
"name":"flag tilting"
},
"flag_fall":{
"unit":"status",
"name":"flag free fall"
},
"flag_impact_x":{
"unit":"status",
"name":"flag impact x-axis"
},
"flag_impact_y":{
"unit":"status",
"name":"flag impact y-axis"
},
"flag_impact_z":{
"unit":"status",
"name":"flag impact z-axis"
},
"uptime":{
"unit":"s",
"name":"duration"
},
"batt":{
"unit":"%",
"name":"battery"
}
}
})"""";*/
6 changes: 6 additions & 0 deletions tests/BLE/test_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ const char* expected_mfg[] = {
"{\"brand\":\"Govee\",\"model\":\"Smart Thermo-Hygrometer\",\"model_id\":\"H5100/01/02/04/05/08/74/77\",\"type\":\"THB\",\"cidc\":false,\"acts\":true,\"tempc\":1.7,\"tempf\":35.06,\"batt\":67}",
"{\"brand\":\"Govee\",\"model\":\"Smart Thermo-Hygrometer\",\"model_id\":\"H5100/01/02/04/05/08/74/77\",\"type\":\"THB\",\"cidc\":false,\"acts\":true,\"tempc\":-3.6,\"tempf\":25.52,\"batt\":35}",
"{\"brand\":\"Govee\",\"model\":\"Smart Thermo-Hygrometer\",\"model_id\":\"H5100/01/02/04/05/08/74/77\",\"type\":\"THB\",\"cidc\":false,\"acts\":true,\"tempc\":-8.4,\"tempf\":16.88,\"batt\":4}",
"{\"brand\":\"MikroTik\",\"model\":\"TG-BT5-IN/-OUT\",\"model_id\":\"TG-BT5\",\"type\":\"ACEL\",\"track\":true,\"tempc\":28.625,\"tempf\":83.525,\"accx\":0,\"accy\":0,\"accz\":0.0078125,\"flag_reed\":false,\"flag_tilt\":false,\"flag_fall\":false,\"flag_impact_x\":true,\"flag_impact_y\":true,\"flag_impact_z\":false,\"uptime\":5703825,\"batt\":95}",
"{\"brand\":\"MikroTik\",\"model\":\"TG-BT5-IN/-OUT\",\"model_id\":\"TG-BT5\",\"type\":\"ACEL\",\"track\":true,\"tempc\":25.62890625,\"tempf\":78.13203125,\"accx\":-0.00390625,\"accy\":-0.0078125,\"accz\":0,\"flag_reed\":true,\"flag_tilt\":false,\"flag_fall\":false,\"flag_impact_x\":true,\"flag_impact_y\":false,\"flag_impact_z\":true,\"uptime\":744,\"batt\":100}",
};

const char* expected_name_uuid_mfgsvcdata[] = {
Expand Down Expand Up @@ -709,6 +711,8 @@ const char* test_mfgdata[][3] = {
{"H5108", "GV51082A7E", "010001010044c0430000"},
{"H5108", "GV51082A7E", "01000101808ef8230000"},
{"H5108", "GV51082A7E", "01000101814a78040000"},
{"Mikrotik", "TG-BT5-IN/-OUT", "4f090100cea6000000000200a01c91085700185f"},
{"Mikrotik", "TG-BT5-IN/-OUT", "4f0901009e11fffffeff0000a119e802000029e4"},
};

TheengsDecoder::BLE_ID_NUM test_mfgdata_id_num[]{
Expand Down Expand Up @@ -880,6 +884,8 @@ TheengsDecoder::BLE_ID_NUM test_mfgdata_id_num[]{
TheengsDecoder::BLE_ID_NUM::H5102,
TheengsDecoder::BLE_ID_NUM::H5102,
TheengsDecoder::BLE_ID_NUM::H5102,
TheengsDecoder::BLE_ID_NUM::TGBT5,
TheengsDecoder::BLE_ID_NUM::TGBT5,
};

// uuid test input [test name] [device name] [uuid] [manufacturer data] [service data]
Expand Down

0 comments on commit 50f9ab2

Please sign in to comment.