Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodOn NIU smart button decoder #515

Merged
merged 7 commits into from
Feb 17, 2024
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
23 changes: 23 additions & 0 deletions docs/devices/NODONNIU.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# NodOn NIU smart button

|Model Id|[NODONNIU](https://github.com/theengs/decoder/blob/development/src/devices/NODONNIU_json.h)|
|-|-|
|Brand|NodOn|
|Model|NIU smart button|
|Short Description|Bluetooth smart button|
|Communication|BLE broadcast|
|Frequency|2.4Ghz|
|Power Source|CR2032|
|Exchanged Data|button press type, color, battery|
|Encrypted|No|
|Device Tracker|✅|

The button press type is encoded as:

* 1 - Single short click
* 2 - Double click
* 3 - Triple click
* 4 - Quadruple click
* 5 - Quintuple click
* 9 - Long press
* 10 - Button release
8 changes: 4 additions & 4 deletions docs/devices/SBBT-002C.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
The button press type is encoded as:

* 0 - None (sent every 8 seconds if beacon mode is enabled)
* 1 - Press
* 2 - Double press
* 3 - Triple press
* 4 - Long press
* 1 - Single short click
* 2 - Double click
* 3 - Triple click
* 9 - Long press
10 changes: 8 additions & 2 deletions src/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,14 @@ int TheengsDecoder::decodeBLEJson(JsonObject& jsondata) {
JsonArray lookup = prop["lookup"];
for (unsigned int i = 0; i < lookup.size(); i += 2) {
if (lookup[i].as<std::string>() == value) {
value = lookup[i + 1].as<std::string>();
jsondata[sanitizeJsonKey(kv.key().c_str())] = value;
if (lookup[i + 1].as<std::string>() != lookup[i + 1]) {
int valueint = lookup[i + 1].as<int>();
jsondata[sanitizeJsonKey(kv.key().c_str())] = valueint;
} else {
value = lookup[i + 1].as<std::string>();
jsondata[sanitizeJsonKey(kv.key().c_str())] = value;
}

success = i_main;
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class TheengsDecoder {
H5179,
HHCCJCY10,
MUE4094RT,
NODONNIU,
MOKOBEACON,
MOKOBEACONXPRO,
INODEEM,
Expand Down
2 changes: 2 additions & 0 deletions src/devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "devices/MBXPRO_json.h"
#include "devices/MS_CDP_json.h"
#include "devices/MUE4094RT_json.h"
#include "devices/NODONNIU_json.h"
#include "devices/Miband_json.h"
#include "devices/XMTZC04HMKG_json.h"
#include "devices/XMTZC04HMLB_json.h"
Expand Down Expand Up @@ -156,6 +157,7 @@ const char* _devices[][2] = {
{_H5179_json, _H5179_json_props},
{_HHCCJCY10_json, _HHCCJCY10_json_props},
{_MUE4094RT_json, _MUE4094RT_json_props},
{_NODONNIU_json, _NODONNIU_json_props},
{_Mokobeacon_json, _Mokobeacon_json_props},
{_MBXPRO_json, _MBXPRO_json_props},
{_iNodeEM_json, _iNodeEM_json_props},
Expand Down
59 changes: 59 additions & 0 deletions src/devices/NODONNIU_json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const char* _NODONNIU_json = "{\"brand\":\"NodOn\",\"model\":\"NIU smart button\",\"model_id\":\"NODONNIU\",\"tag\":\"110e\",\"condition\":[\"servicedata\",\"=\",32,\"&\",\"uuid\",\"index\",0,\"0000\"],\"properties\":{\"button\":{\"decoder\":[\"string_from_hex_data\",\"servicedata\",30,2],\"lookup\":[\"01\",1,\"02\",2,\"03\",9,\"04\",10,\"05\",3,\"06\",4,\"07\",5]},\"color\":{\"decoder\":[\"string_from_hex_data\",\"servicedata\",20,4],\"lookup\":[\"0002\",\"White\",\"0003\",\"TechBlue\",\"0004\",\"CozyGrey\",\"0005\",\"Wazabi\",\"0006\",\"Lagoon\",\"0007\",\"Softberry\"]},\"batt\":{\"decoder\":[\"value_from_hex_data\",\"servicedata\",24,2,false,false],\"post_proc\":[\"&\",127]}}}";

/*
R""""(
{
"brand":"NodOn",
"model":"NIU smart button",
"model_id":"NODONNIU",
"tag":"110e",
"condition":["servicedata", "=", 32, "&", "uuid", "index", 0, "0000"],
"properties":{
"button":{
"decoder":["string_from_hex_data", "servicedata", 30, 2],
"lookup":["01", 1,
"02", 2,
"03", 9,
"04", 10,
"05", 3,
"06", 4,
"07", 5]
},
"color":{
"decoder":["string_from_hex_data", "servicedata", 20, 4],
"lookup":["0002", "White",
"0003", "TechBlue",
"0004", "CozyGrey",
"0005", "Wazabi",
"0006", "Lagoon",
"0007", "Softberry"]
},
"batt":{
"decoder":["value_from_hex_data", "servicedata", 24, 2, false, false],
"post_proc":["&", 127]
}
}
})"""";
*/

const char* _NODONNIU_json_props = "{\"properties\":{\"button\":{\"unit\":\"int\",\"name\":\"button press type\"},\"color\":{\"unit\":\"string\",\"name\":\"color\"},\"batt\":{\"unit\":\"%\",\"name\":\"battery\"}}}";

/*
R""""(
{
"properties": {
"button":{
"unit":"int",
"name":"button press type"
},
"color":{
"unit":"string",
"name":"color"
},
"batt":{
"unit":"%",
"name":"battery"
}
}
})"""";
*/
17 changes: 11 additions & 6 deletions src/devices/SBBT_002C_json.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const char* _SBBT_002C_json = "{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1\",\"model_id\":\"SBBT-002C\",\"tag\":\"1106\",\"condition\":[\"servicedata\",\"=\",14,\"index\",0,\"40\",\"|\",\"servicedata\",\"=\",14,\"index\",0,\"44\",\"&\",\"uuid\",\"index\",0,\"fcd2\",\"&\",\"name\",\"index\",0,\"SBBT-002C\"],\"properties\":{\"packet\":{\"condition\":[\"servicedata\",2,\"00\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",4,2,false,false]},\"batt\":{\"condition\":[\"servicedata\",6,\"01\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",8,2,false,false]},\"press\":{\"condition\":[\"servicedata\",10,\"3a\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",12,2,false,false]},\"mac\":{\"condition\":[\"manufacturerdata\",\"=\",30],\"decoder\":[\"revmac_from_hex_data\",\"manufacturerdata\",18]}}}";
const char* _SBBT_002C_json = "{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1\",\"model_id\":\"SBBT-002C\",\"tag\":\"1106\",\"condition\":[\"servicedata\",\"=\",14,\"index\",0,\"40\",\"|\",\"servicedata\",\"=\",14,\"index\",0,\"44\",\"&\",\"uuid\",\"index\",0,\"fcd2\",\"&\",\"name\",\"index\",0,\"SBBT-002C\"],\"properties\":{\"packet\":{\"condition\":[\"servicedata\",2,\"00\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",4,2,false,false]},\"batt\":{\"condition\":[\"servicedata\",6,\"01\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",8,2,false,false]},\"button\":{\"condition\":[\"servicedata\",10,\"3a\"],\"decoder\":[\"string_from_hex_data\",\"servicedata\",12,2],\"lookup\":[\"00\",0,\"01\",1,\"02\",2,\"03\",3,\"04\",9]},\"mac\":{\"condition\":[\"manufacturerdata\",\"=\",30],\"decoder\":[\"revmac_from_hex_data\",\"manufacturerdata\",18]}}}";
/*R""""(
{
"brand":"Shelly",
Expand All @@ -15,9 +15,14 @@ const char* _SBBT_002C_json = "{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Butto
"condition":["servicedata", 6, "01"],
"decoder":["value_from_hex_data", "servicedata", 8, 2, false, false]
},
"press":{
"button":{
"condition":["servicedata", 10, "3a"],
"decoder":["value_from_hex_data", "servicedata", 12, 2, false, false]
"decoder":["string_from_hex_data", "servicedata", 12, 2],
"lookup":["00", 0,
"01", 1,
"02", 2,
"03", 3,
"04", 9]
},
"mac":{
"condition":["manufacturerdata", "=", 30],
Expand All @@ -26,7 +31,7 @@ const char* _SBBT_002C_json = "{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Butto
}
})"""";*/

const char* _SBBT_002C_json_props = "{\"properties\":{\"packet\":{\"unit\":\"int\",\"name\":\"packet id\"},\"batt\":{\"unit\":\"%\",\"name\":\"battery\"},\"press\":{\"unit\":\"int\",\"name\":\"press type\"},\"mac\":{\"unit\":\"string\",\"name\":\"MAC address\"}}}";
const char* _SBBT_002C_json_props = "{\"properties\":{\"packet\":{\"unit\":\"int\",\"name\":\"packet id\"},\"batt\":{\"unit\":\"%\",\"name\":\"battery\"},\"button\":{\"unit\":\"int\",\"name\":\"button press type\"},\"mac\":{\"unit\":\"string\",\"name\":\"MAC address\"}}}";
/*R""""(
{
"properties":{
Expand All @@ -38,9 +43,9 @@ const char* _SBBT_002C_json_props = "{\"properties\":{\"packet\":{\"unit\":\"int
"unit":"%",
"name":"battery"
},
"press":{
"button":{
"unit":"int",
"name":"press type"
"name":"button press type"
},
"mac":{
"unit":"string",
Expand Down
27 changes: 21 additions & 6 deletions tests/BLE/test_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ const char* expected_name_uuid_mfgsvcdata[] = {
};

const char* expected_name_mac_uuid_mfgsvcdata[] = {
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1\",\"model_id\":\"SBBT-002C\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"packet\":29,\"batt\":100,\"press\":1,\"mac\":\"BC:02:6E:AA:BB:CC\"}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1\",\"model_id\":\"SBBT-002C\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"packet\":29,\"batt\":100,\"button\":1,\"mac\":\"BC:02:6E:AA:BB:CC\"}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1 encrypted\",\"model_id\":\"SBBT_002C_ENCR\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"encr\":2,\"cipher\":\"62511158bd25\",\"ctr\":\"b8f09364\",\"mic\":\"5b573115\",\"mac\":\"BC:02:6E:AA:BB:CC\"}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Door/Window\",\"model_id\":\"SBDW-002C\",\"type\":\"CTMO\",\"acts\":true,\"cont\":true,\"packet\":93,\"batt\":100,\"lux\":87,\"open\":true,\"rot\":40.6,\"mac\":\"3C:2E:F5:AA:BB:CC\"}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Door/Window\",\"model_id\":\"SBDW-002C\",\"type\":\"CTMO\",\"acts\":true,\"cont\":true,\"packet\":86,\"batt\":100,\"lux\":673,\"open\":false,\"rot\":0,\"mac\":\"3C:2E:F5:AA:BB:CC\"}",
Expand Down Expand Up @@ -196,11 +196,11 @@ const char* expected_uuid_name_svcdata[] = {
"{\"brand\":\"Xiaomi\",\"model\":\"TH Sensor\",\"model_id\":\"LYWSD03MMC/MJWSD05MMC_PVVX\",\"type\":\"THB\",\"tempc\":19.23,\"tempf\":66.614,\"hum\":48.36,\"batt\":100,\"volt\":2.959,\"mac\":\"A4:C1:38:52:8F:62\"}",
"{\"brand\":\"Xiaomi\",\"model\":\"TH Sensor\",\"model_id\":\"LYWSD03MMC/MJWSD05MMC_PVVX\",\"type\":\"THB\",\"tempc\":-6.7,\"tempf\":19.94,\"hum\":50.53,\"batt\":100,\"volt\":3.143,\"mac\":\"A4:C1:38:CF:01:56\"}",
"{\"brand\":\"Xiaomi\",\"model\":\"TH Sensor\",\"model_id\":\"LYWSD03MMC/MJWSD05MMC_PVVX\",\"type\":\"THB\",\"tempc\":24.28,\"tempf\":75.704,\"hum\":43.65,\"batt\":100,\"volt\":3.125,\"mac\":\"A4:C1:38:DF:DE:2F\"}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1\",\"model_id\":\"SBBT-002C\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"packet\":29,\"batt\":100,\"press\":1}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1\",\"model_id\":\"SBBT-002C\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"packet\":30,\"batt\":100,\"press\":2}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1\",\"model_id\":\"SBBT-002C\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"packet\":31,\"batt\":100,\"press\":3}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1\",\"model_id\":\"SBBT-002C\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"packet\":32,\"batt\":100,\"press\":4}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1\",\"model_id\":\"SBBT-002C\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"packet\":171,\"batt\":100,\"press\":1}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1\",\"model_id\":\"SBBT-002C\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"packet\":29,\"batt\":100,\"button\":1}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1\",\"model_id\":\"SBBT-002C\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"packet\":30,\"batt\":100,\"button\":2}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1\",\"model_id\":\"SBBT-002C\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"packet\":31,\"batt\":100,\"button\":3}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1\",\"model_id\":\"SBBT-002C\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"packet\":32,\"batt\":100,\"button\":9}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1\",\"model_id\":\"SBBT-002C\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"packet\":171,\"batt\":100,\"button\":1}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1 encrypted\",\"model_id\":\"SBBT_002C_ENCR\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"encr\":2,\"cipher\":\"62511158bd25\",\"ctr\":\"b8f09364\",\"mic\":\"5b573115\"}",
"{\"brand\":\"Xiaomi\",\"model\":\"TH Sensor\",\"model_id\":\"LYWSD03MMC/MJWSD05MMC_PVVX_ENCR\",\"type\":\"THB\",\"encr\":1,\"cipher\":\"ef56583dd420\",\"ctr\":\"23\",\"mic\":\"50fe8e4d\"}",
"{\"brand\":\"Xiaomi\",\"model\":\"TH Sensor\",\"model_id\":\"LYWSD03MMC/MJWSD05MMC_PVVX_DECR\",\"type\":\"THB\",\"tempc\":24.60,\"tempf\":76.28,\"hum\":43.54,\"batt\":100}",
Expand Down Expand Up @@ -344,6 +344,11 @@ const char* expected_uuid[] = {
"{\"brand\":\"Xiaomi\",\"model\":\"MiLamp\",\"model_id\":\"MUE4094RT\",\"type\":\"CTMO\",\"cont\":true,\"motion\":true,\"darkness\":2}",
"{\"brand\":\"Xiaomi\",\"model\":\"MiLamp\",\"model_id\":\"MUE4094RT\",\"type\":\"CTMO\",\"cont\":true,\"mac\":\"AA:BB:CC:DD:EE:FF\"}",
"{\"brand\":\"Jaalee\",\"model\":\"TH sensor\",\"model_id\":\"F525/F51C\",\"type\":\"THB\",\"acts\":true,\"tempc\":24.39116503,\"tempf\":75.90409705,\"hum\":23.86816205,\"batt\":100}",
"{\"brand\":\"NodOn\",\"model\":\"NIU smart button\",\"model_id\":\"NODONNIU\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"track\":true,\"button\":1,\"color\":\"Lagoon\",\"batt\":99}",
"{\"brand\":\"NodOn\",\"model\":\"NIU smart button\",\"model_id\":\"NODONNIU\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"track\":true,\"button\":2,\"color\":\"Lagoon\",\"batt\":99}",
"{\"brand\":\"NodOn\",\"model\":\"NIU smart button\",\"model_id\":\"NODONNIU\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"track\":true,\"button\":9,\"color\":\"Lagoon\",\"batt\":96}",
"{\"brand\":\"NodOn\",\"model\":\"NIU smart button\",\"model_id\":\"NODONNIU\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"track\":true,\"button\":10,\"color\":\"Lagoon\",\"batt\":98}",
"{\"brand\":\"NodOn\",\"model\":\"NIU smart button\",\"model_id\":\"NODONNIU\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"track\":true,\"button\":3,\"color\":\"CozyGrey\",\"batt\":89}",
};

const char* expected_mac_mfg[] = {
Expand Down Expand Up @@ -942,6 +947,11 @@ const char* test_uuid[][4] = {
{"MiLamp", "0xfe95", "servicedata", "4030dd030203000101"},
{"MiLamp", "0xfe95", "servicedata", "3030dd0301ffeeddccbbaa0d"},
{"Jaalee", "0xf51c", "manufacturerdata", "4c000215ebefd08370a247c89837e7b5634df52565823d1acc64"},
{"NodOn NIU", "0x0000", "servicedata", "02599c37d90287a521520006635ab801"},
{"NodOn NIU", "0x0000", "servicedata", "02599c37d90287a52152000663ee4b02"},
{"NodOn NIU", "0x0000", "servicedata", "02599c37d90287a52152000660259003"},
{"NodOn NIU", "0x0000", "servicedata", "02599c37d90287a521520006622b8104"},
{"NodOn NIU", "0x0000", "servicedata", "02599c37d90287a521520004595eb905"},
};

TheengsDecoder::BLE_ID_NUM test_uuid_id_num[]{
Expand Down Expand Up @@ -1071,6 +1081,11 @@ TheengsDecoder::BLE_ID_NUM test_uuid_id_num[]{
TheengsDecoder::BLE_ID_NUM::MUE4094RT,
TheengsDecoder::BLE_ID_NUM::MUE4094RT,
TheengsDecoder::BLE_ID_NUM::JAALEE,
TheengsDecoder::BLE_ID_NUM::NODONNIU,
TheengsDecoder::BLE_ID_NUM::NODONNIU,
TheengsDecoder::BLE_ID_NUM::NODONNIU,
TheengsDecoder::BLE_ID_NUM::NODONNIU,
TheengsDecoder::BLE_ID_NUM::NODONNIU,
};

// MAC manufacturer data test input [test name] [mac] [data]
Expand Down
Loading