Skip to content

Commit

Permalink
Button adjustments
Browse files Browse the repository at this point in the history
NodON NIU and Shelly button adjustments
  • Loading branch information
DigiH committed Feb 16, 2024
1 parent a94dadb commit 87db609
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 23 deletions.
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 - 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 - 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
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
22 changes: 11 additions & 11 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,11 +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\":\"short click\",\"color\":\"Lagoon\",\"batt\":99}",
"{\"brand\":\"NodOn\",\"model\":\"NIU smart button\",\"model_id\":\"NODONNIU\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"track\":true,\"button\":\"double click\",\"color\":\"Lagoon\",\"batt\":99}",
"{\"brand\":\"NodOn\",\"model\":\"NIU smart button\",\"model_id\":\"NODONNIU\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"track\":true,\"button\":\"long press\",\"color\":\"Lagoon\",\"batt\":96}",
"{\"brand\":\"NodOn\",\"model\":\"NIU smart button\",\"model_id\":\"NODONNIU\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"track\":true,\"button\":\"button release\",\"color\":\"Lagoon\",\"batt\":98}",
"{\"brand\":\"NodOn\",\"model\":\"NIU smart button\",\"model_id\":\"NODONNIU\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"track\":true,\"button\":\"triple click\",\"color\":\"CozyGrey\",\"batt\":89}",
"{\"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

0 comments on commit 87db609

Please sign in to comment.