diff --git a/docs/devices/NODONNIU.md b/docs/devices/NODONNIU.md new file mode 100644 index 00000000..a84cd706 --- /dev/null +++ b/docs/devices/NODONNIU.md @@ -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 diff --git a/docs/devices/SBBT-002C.md b/docs/devices/SBBT-002C.md index 0258d2bf..84f7c016 100644 --- a/docs/devices/SBBT-002C.md +++ b/docs/devices/SBBT-002C.md @@ -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 diff --git a/src/decoder.cpp b/src/decoder.cpp index 8dc7d817..b5eecc63 100644 --- a/src/decoder.cpp +++ b/src/decoder.cpp @@ -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() == value) { - value = lookup[i + 1].as(); - jsondata[sanitizeJsonKey(kv.key().c_str())] = value; + if (lookup[i + 1].as() != lookup[i + 1]) { + int valueint = lookup[i + 1].as(); + jsondata[sanitizeJsonKey(kv.key().c_str())] = valueint; + } else { + value = lookup[i + 1].as(); + jsondata[sanitizeJsonKey(kv.key().c_str())] = value; + } + success = i_main; break; } diff --git a/src/decoder.h b/src/decoder.h index b6504094..985ae3fa 100644 --- a/src/decoder.h +++ b/src/decoder.h @@ -89,6 +89,7 @@ class TheengsDecoder { H5179, HHCCJCY10, MUE4094RT, + NODONNIU, MOKOBEACON, MOKOBEACONXPRO, INODEEM, diff --git a/src/devices.h b/src/devices.h index 8b28cb9d..8ba2d704 100644 --- a/src/devices.h +++ b/src/devices.h @@ -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" @@ -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}, diff --git a/src/devices/NODONNIU_json.h b/src/devices/NODONNIU_json.h new file mode 100644 index 00000000..014d603a --- /dev/null +++ b/src/devices/NODONNIU_json.h @@ -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" + } + } +})""""; +*/ diff --git a/src/devices/SBBT_002C_json.h b/src/devices/SBBT_002C_json.h index 21c2296d..75c5f06a 100644 --- a/src/devices/SBBT_002C_json.h +++ b/src/devices/SBBT_002C_json.h @@ -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", @@ -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], @@ -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":{ @@ -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", diff --git a/tests/BLE/test_ble.cpp b/tests/BLE/test_ble.cpp index b79a63d7..291ec9c0 100644 --- a/tests/BLE/test_ble.cpp +++ b/tests/BLE/test_ble.cpp @@ -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\"}", @@ -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}", @@ -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[] = { @@ -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[]{ @@ -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]