Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions docs/participate/adding-decoders.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ Each device should also have an encoded **tag** property to, at the minimum, def
</thead>
<tbody>
<tr>
<td rowspan=23>Byte[0]</td>
<td rowspan=23>Device Type > "type":</td>
<td rowspan=24>Byte[0]</td>
<td rowspan=24>Device Type > "type":</td>
<td rowspan=1>0 - Reserved</td>
</tr>
<tr>
Expand Down Expand Up @@ -115,7 +115,10 @@ Each device should also have an encoded **tag** property to, at the minimum, def
<td rowspan=1>19 - WIND - wind speed anemometers</td>
</tr>
<tr>
<td rowspan=1>20-253 - Reserved</td>
<td rowspan=1>20 - ENRG - energy producing, monitoring and storing devices</td>
</tr>
<tr>
<td rowspan=1>20-253 - Reserved for future use</td>
</tr>
<tr>
<td rowspan=1>254 - RMAC - known random MAC address devices</td>
Expand Down Expand Up @@ -148,13 +151,16 @@ Each device should also have an encoded **tag** property to, at the minimum, def
<td rowspan=1>Bit[0] Is NOT Company ID compliant > "cidc":</td>
</tr>
<tr>
<td rowspan=2>Byte[2]</td>
<td rowspan=2>Encryption Model > "encr":</td>
<td rowspan=3>Byte[2]</td>
<td rowspan=3>Encryption Model > "encr":</td>
<td rowspan=1>1 - LYWSD03MMC PVVX</td>
</tr>
<tr>
<td rowspan=1>2 - BTHome v2</td>
</tr>
<tr>
<td rowspan=1>3 - Victron Energy</td>
</tr>
</tbody>
</table>

Expand Down
7 changes: 5 additions & 2 deletions src/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,13 @@ int TheengsDecoder::decodeBLEJson(JsonObject& jsondata) {
doc["type"] = "BTN"; // Button
break;
case 18:
doc["type"] = "AUDIO"; // Button
doc["type"] = "AUDIO"; // Audio
break;
case 19:
doc["type"] = "WIND"; // Button
doc["type"] = "WIND"; // Anemometers
break;
case 20:
doc["type"] = "ENRG"; // Energy
break;
case 254:
doc["type"] = "RMAC"; // random MAC address devices
Expand Down
2 changes: 2 additions & 0 deletions src/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ class TheengsDecoder {
SPHT,
SERVICE_DATA,
UT363BT,
VICTSBP_ENCR,
VICTSBP,
SE_RHT,
SE_TEMP,
SE_TPROBE,
Expand Down
4 changes: 4 additions & 0 deletions src/devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
#include "devices/SensorP_HT_json.h"
#include "devices/ServiceData_json.h"
#include "devices/UT363BT_json.h"
#include "devices/VICTRON_DCDC_ENCR_json.h"
#include "devices/VICTRON_DCDC_json.h"
#include "devices/SE_RHT_json.h"
#include "devices/SE_TEMP_json.h"
#include "devices/SE_TPROBE_json.h"
Expand Down Expand Up @@ -251,6 +253,8 @@ const char* _devices[][2] = {
{_SensorPush_HT_json, _SensorPush_HT_json_props},
{_ServiceData_json, _ServiceData_json_props},
{_UT363BT_json, _UT363BT_json_props},
{_VICTSBP_ENCR_json, _VICTSBP_ENCR_json_props},
{_VICTSBP_json, _VICTSBP_json_props},
{_SE_RHT_json, _SE_RHT_json_props},
{_SE_TEMP_json, _SE_TEMP_json_props},
{_SE_TPROBE_json, _SE_TPROBE_json_props},
Expand Down
39 changes: 39 additions & 0 deletions src/devices/VICTRON_DCDC_ENCR_json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const char* _VICTSBP_ENCR_json = "{\"brand\":\"Victron Energy\",\"model\":\"Smart BatteryProtect encrypted\",\"model_id\":\"VICTSBP_ENCR\",\"tag\":\"140003\",\"condition\":[\"manufacturerdata\",\"=\",50,\"index\",0,\"e10210\",\"&\",\"manufacturerdata\",\"index\",12,\"09\"],\"properties\":{\"cipher\":{\"decoder\":[\"string_from_hex_data\",\"manufacturerdata\",20,30]},\"ctr\":{\"decoder\":[\"string_from_hex_data\",\"manufacturerdata\",14,4,true]},\"mic\":{\"decoder\":[\"string_from_hex_data\",\"manufacturerdata\",18,2]}}}";
/*R""""(
{
"brand":"Victron Energy",
"model":"Smart BatteryProtect encrypted",
"model_id":"VICTSBP_ENCR",
"tag":"140003",
"condition":["manufacturerdata", "=", 50, "index", 0, "e10210", "&", "manufacturerdata", "index", 12, "09"],
"properties":{
"cipher":{
"decoder":["string_from_hex_data", "manufacturerdata", 20, 30]
},
"ctr":{
"decoder":["string_from_hex_data", "manufacturerdata", 14, 4, true]
},
"mic":{
"decoder":["string_from_hex_data", "manufacturerdata", 18, 2]
}
}
})"""";*/

const char* _VICTSBP_ENCR_json_props = "{\"properties\":{\"cipher\":{\"unit\":\"hex\",\"name\":\"ciphertext\"},\"ctr\":{\"unit\":\"hex\",\"name\":\"counter\"},\"mic\":{\"unit\":\"hex\",\"name\":\"message integrity check\"}}}";
/*R""""(
{
"properties":{
"cipher":{
"unit":"hex",
"name":"ciphertext"
},
"ctr":{
"unit":"hex",
"name":"counter"
},
"mic":{
"unit":"hex",
"name":"message integrity check"
}
}
})"""";*/
111 changes: 111 additions & 0 deletions src/devices/VICTRON_DCDC_json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
const char* _VICTSBP_json = "{\"brand\":\"Victron Energy\",\"model\":\"Smart BatteryProtect\",\"model_id\":\"VICTSBP\",\"tag\":\"1400\",\"condition\":[\"manufacturerdata\",\"=\",50,\"index\",0,\"e10211\",\"&\",\"manufacturerdata\",\"index\",12,\"09ffff\"],\"properties\":{\"device_state\":{\"condition\":[\"manufacturerdata\",20,\"!\",\"ff\"],\"decoder\":[\"string_from_hex_data\",\"manufacturerdata\",20,2],\"lookup\":[\"00\",\"off\",\"01\",\"low power\",\"02\",\"fault\",\"03\",\"bulk\",\"04\",\"absorption\",\"05\",\"float\",\"06\",\"storage\",\"07\",\"equalize manual\",\"09\",\"inverting\",\"0b\",\"power_supply\",\"f5\",\"starting up\",\"f6\",\"repeated absorption\",\"f7\",\"recondition\",\"f8\",\"battery safe\",\"f9\",\"active\",\"fc\",\"external control\"]},\"output_state\":{\"condition\":[\"manufacturerdata\",22,\"!\",\"ff\"],\"decoder\":[\"string_from_hex_data\",\"manufacturerdata\",22,2],\"lookup\":[\"00\",\"off\",\"01\",\"on\"]},\"error_code\":{\"condition\":[\"manufacturerdata\",24,\"!\",\"ff\",\"&\",\"manufacturerdata\",24,\"!\",\"00\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",24,2]},\"alarm_reason\":{\"condition\":[\"manufacturerdata\",26,\"!\",\"0000\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",26,4]},\"warning_reason\":{\"condition\":[\"manufacturerdata\",30,\"!\",\"0000\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",30,4]},\"volt_in\":{\"condition\":[\"manufacturerdata\",34,\"!\",\"7fff\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",34,4,true,true],\"post_proc\":[\"/\",100]},\"volt_out\":{\"condition\":[\"manufacturerdata\",38,\"!\",\"7fff\"],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",38,4,true,false],\"post_proc\":[\"/\",100]},\"off_reason\":{\"decoder\":[\"string_from_hex_data\",\"manufacturerdata\",42,8],\"lookup\":[\"00000000\",\"NO_REASON\",\"01000000\",\"NO_INPUT_POWER\",\"02000000\",\"SWITCHED_OFF_SWITCH\",\"04000000\",\"SWITCHED_OFF_REGISTER\",\"08000000\",\"REMOTE_INPUT\",\"10000000\",\"PROTECTION_ACTIVE\",\"20000000\",\"PAY_AS_YOU_GO_OUT_OF_CREDIT\",\"40000000\",\"BMS\",\"80000000\",\"ENGINE_SHUTDOWN\",\"00010000\",\"ANALYSING_INPUT_VOLTAGE\"]}}}";
/*R""""(
{
"brand":"Victron Energy",
"model":"Smart BatteryProtect",
"model_id":"VICTSBP",
"tag":"1400",
"condition":["manufacturerdata", "=", 50, "index", 0, "e10211", "&", "manufacturerdata", "index", 12, "09ffff"],
"properties":{
"device_state":{
"condition":["manufacturerdata", 20, "!", "ff"],
"decoder":["string_from_hex_data", "manufacturerdata", 20, 2],
"lookup":["00", "off",
"01", "low power",
"02", "fault",
"03", "bulk",
"04", "absorption",
"05", "float",
"06", "storage",
"07", "equalize manual",
"09", "inverting",
"0b", "power_supply",
"f5", "starting up",
"f6", "repeated absorption",
"f7", "recondition",
"f8", "battery safe",
"f9", "active",
"fc", "external control"]
},
"output_state":{
"condition":["manufacturerdata", 22, "!", "ff"],
"decoder":["string_from_hex_data", "manufacturerdata", 22, 2],
"lookup":["00", "off",
"01", "on"]
},
"error_code":{
"condition":["manufacturerdata", 24, "!", "ff", "&", "manufacturerdata", 24, "!", "00"],
"decoder":["value_from_hex_data", "manufacturerdata", 24, 2]
},
"alarm_reason":{
"condition":["manufacturerdata", 26, "!", "0000"],
"decoder":["value_from_hex_data", "manufacturerdata", 26, 4]
},
"warning_reason":{
"condition":["manufacturerdata", 30, "!", "0000"],
"decoder":["value_from_hex_data", "manufacturerdata", 30, 4]
},
"volt_in":{
"condition":["manufacturerdata", 34, "!", "7fff"],
"decoder":["value_from_hex_data", "manufacturerdata", 34, 4, true, true],
"post_proc":["/", 100]
},
"volt_out":{
"condition":["manufacturerdata", 38, "!", "7fff"],
"decoder":["value_from_hex_data", "manufacturerdata", 38, 4, true, false],
"post_proc":["/", 100]
},
"off_reason":{
"decoder":["string_from_hex_data", "manufacturerdata", 42, 8],
"lookup":["00000000", "NO_REASON",
"01000000", "NO_INPUT_POWER",
"02000000", "SWITCHED_OFF_SWITCH",
"04000000", "SWITCHED_OFF_REGISTER",
"08000000", "REMOTE_INPUT",
"10000000", "PROTECTION_ACTIVE",
"20000000", "PAY_AS_YOU_GO_OUT_OF_CREDIT",
"40000000", "BMS",
"80000000", "ENGINE_SHUTDOWN",
"00010000", "ANALYSING_INPUT_VOLTAGE"]
}
}
})"""";*/

const char* _VICTSBP_json_props = "{\"properties\":{\"device_state\":{\"unit\":\"string\",\"name\":\"device state\"},\"output_state\":{\"unit\":\"string\",\"name\":\"output state\"},\"error_code\":{\"unit\":\"int\",\"name\":\"error code\"},\"alarm_reason\":{\"unit\":\"int\",\"name\":\"alarm reason\"},\"warning_reason\":{\"unit\":\"int\",\"name\":\"warning reason\"},\"volt_in\":{\"unit\":\"V\",\"name\":\"voltage\"},\"volt_out\":{\"unit\":\"V\",\"name\":\"voltage\"},\"off_reason\":{\"unit\":\"string\",\"name\":\"off reason\"}}}";
/*R""""(
{
"properties":{
"device_state":{
"unit":"string",
"name":"device state"
},
"output_state":{
"unit":"string",
"name":"output state"
},
"error_code":{
"unit":"int",
"name":"error code"
},
"alarm_reason":{
"unit":"int",
"name":"alarm reason"
},
"warning_reason":{
"unit":"int",
"name":"warning reason"
},
"volt_in": {
"unit": "V",
"name": "voltage"
},
"volt_out": {
"unit": "V",
"name": "voltage"
},
"off_reason":{
"unit":"string",
"name":"off reason"
}
}
})"""";*/
21 changes: 21 additions & 0 deletions tests/BLE/test_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ const char* expected_mfg[] = {
"{\"brand\":\"Govee\",\"model\":\"Bluetooth BBQ Thermometer\",\"model_id\":\"H5055\",\"type\":\"BBQ\",\"cidc\":false,\"tempc5\":21,\"tempf5\":69.8,\"tempc6\":21,\"tempf6\":69.8,\"batt\":100}",
"{\"brand\":\"Govee\",\"model\":\"Bluetooth BBQ Thermometer\",\"model_id\":\"H5055\",\"type\":\"BBQ\",\"cidc\":false,\"tempc3\":23,\"tempf3\":73.4,\"tempc4\":21,\"tempf4\":69.8,\"batt\":100}",
"{\"brand\":\"Govee\",\"model\":\"Bluetooth BBQ Thermometer\",\"model_id\":\"H5055\",\"type\":\"BBQ\",\"cidc\":false,\"tempc1\":26,\"tempf1\":78.8,\"tempc2\":22,\"tempf2\":71.6,\"batt\":100}",
"{\"brand\":\"Victron Energy\",\"model\":\"Smart BatteryProtect encrypted\",\"model_id\":\"VICTSBP_ENCR\",\"type\":\"ENRG\",\"encr\":3,\"cipher\":\"f581a6631c3ddfccaa081fad4da6f4\",\"ctr\":\"a82c\",\"mic\":\"da\"}",
"{\"brand\":\"Victron Energy\",\"model\":\"Smart BatteryProtect\",\"model_id\":\"VICTSBP\",\"type\":\"ENRG\",\"device_state\":\"off\",\"output_state\":\"off\",\"volt_in\":12.8,\"volt_out\":0.1,\"off_reason\":\"REMOTE_INPUT\"}",
"{\"brand\":\"Victron Energy\",\"model\":\"Smart BatteryProtect\",\"model_id\":\"VICTSBP\",\"type\":\"ENRG\",\"device_state\":\"active\",\"output_state\":\"on\",\"volt_in\":13.07,\"volt_out\":13.07,\"off_reason\":\"NO_REASON\"}",
"{\"brand\":\"Victron Energy\",\"model\":\"Smart BatteryProtect\",\"model_id\":\"VICTSBP\",\"type\":\"ENRG\",\"device_state\":\"off\",\"output_state\":\"off\",\"volt_in\":12.76,\"volt_out\":0.11,\"off_reason\":\"REMOTE_INPUT\"}",
"{\"brand\":\"Victron Energy\",\"model\":\"Smart BatteryProtect\",\"model_id\":\"VICTSBP\",\"type\":\"ENRG\",\"device_state\":\"active\",\"output_state\":\"on\",\"volt_in\":12.64,\"volt_out\":12.64,\"off_reason\":\"NO_REASON\"}",
"{\"brand\":\"Victron Energy\",\"model\":\"Smart BatteryProtect\",\"model_id\":\"VICTSBP\",\"type\":\"ENRG\",\"device_state\":\"off\",\"output_state\":\"off\",\"volt_in\":12.74,\"volt_out\":0.12,\"off_reason\":\"SWITCHED_OFF_REGISTER\"}",
"{\"brand\":\"Victron Energy\",\"model\":\"Smart BatteryProtect\",\"model_id\":\"VICTSBP\",\"type\":\"ENRG\",\"device_state\":\"off\",\"output_state\":\"off\",\"volt_in\":12.79,\"volt_out\":0.11,\"off_reason\":\"SWITCHED_OFF_REGISTER\"}",
};

const char* expected_name_uuid_mfgsvcdata[] = {
Expand Down Expand Up @@ -748,6 +755,13 @@ const char* test_mfgdata[][3] = {
{"H5055", "GVH5055", "d596c100648f221500ffff3f00221500ffff3f000000"},
{"H5055", "GVH5055", "d596c1006441221700ffff3f00221500ffff3f000000"},
{"H5055", "GVH5055", "d596c1006401201a00ffff3100221600ffff3f000000"},
{"Victron Smart Battery Protect ENC", "", "e1021000b0a309a82cdaf581a6631c3ddfccaa081fad4da6f4"},
{"Victron Smart Battery Protect", "", "e1021100b0a309ffffda0000000000000000050a0008000000"},
{"Victron Smart Battery Protect", "", "e1021100b0a309ffffdaf90100000000001b051b0500000000"},
{"Victron Smart Battery Protect", "", "e1021100b0a309ffffda00000000000000fc040b0008000000"},
{"Victron Smart Battery Protect", "", "e1021100b0a309ffffdaf9010000000000f004f00400000000"},
{"Victron Smart Battery Protect", "", "e1021100b0a309ffffda00000000000000fa040c0004000000"},
{"Victron Smart Battery Protect", "", "e1021100b0a309ffffda00000000000000ff040b0004000000"},
};

TheengsDecoder::BLE_ID_NUM test_mfgdata_id_num[]{
Expand Down Expand Up @@ -934,6 +948,13 @@ TheengsDecoder::BLE_ID_NUM test_mfgdata_id_num[]{
TheengsDecoder::BLE_ID_NUM::H5055,
TheengsDecoder::BLE_ID_NUM::H5055,
TheengsDecoder::BLE_ID_NUM::H5055,
TheengsDecoder::BLE_ID_NUM::VICTSBP_ENCR,
TheengsDecoder::BLE_ID_NUM::VICTSBP,
TheengsDecoder::BLE_ID_NUM::VICTSBP,
TheengsDecoder::BLE_ID_NUM::VICTSBP,
TheengsDecoder::BLE_ID_NUM::VICTSBP,
TheengsDecoder::BLE_ID_NUM::VICTSBP,
TheengsDecoder::BLE_ID_NUM::VICTSBP,
};

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