diff --git a/README.md b/README.md index 61c8728c..57146125 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Theengs Decoder library translates these data chains into human readable data le It's also a simplified way of defining the thing properties and how to decode these. -Theengs Decoder supports the decoding of [more than 90 Bluetooth devices](https://decoder.theengs.io/devices/devices.html). +Theengs Decoder supports the decoding of [more than 100 Bluetooth devices](https://decoder.theengs.io/devices/devices.html). Theengs Decoder can be used on memory constraint environments like micro controllers (ESP32, ESP8266, Arduino), on a PC or on a Unix server. Unit testing assures that the modification done on the library doesn't affect previous capabilities. diff --git a/docs/README.md b/docs/README.md index 9412e6e7..cf630b35 100644 --- a/docs/README.md +++ b/docs/README.md @@ -16,7 +16,7 @@ Theengs Decoder library translates these data chains into human readable data le It's also a simplified way of defining the thing properties and how to decode these. -Theengs Decoder supports the decoding of [more than 90 Bluetooth devices](https://decoder.theengs.io/devices/devices.html). +Theengs Decoder supports the decoding of [more than 100 Bluetooth devices](https://decoder.theengs.io/devices/devices.html). Theengs Decoder can be used on memory constraint environments like micro controllers (ESP32, ESP8266, Arduino), on a PC or on a Unix server. Unit testing assures that the modification done on the library doesn't affect previous capabilities. diff --git a/docs/devices/SBBT.md b/docs/devices/SBBT.md new file mode 100644 index 00000000..f2566aaa --- /dev/null +++ b/docs/devices/SBBT.md @@ -0,0 +1,12 @@ +# SwitchBot Blind Tilt + +|Model Id|[W270160X](https://github.com/theengs/decoder/blob/development/src/devices/SBBT_json.h)| +|-|-| +|Brand|SwitchBot| +|Model|W270160X| +|Short Description|Venetian blind tilting actor| +|Communication|BLE broadcast| +|Frequency|2.4Ghz| +|Power source|Solar panel| +|Exchanged data|open, direction, motion, calibrated, light level, battery| +|Encrypted|No| diff --git a/docs/devices/devices_template.html b/docs/devices/devices_template.html index d0d1dbb5..be1a4167 100644 --- a/docs/devices/devices_template.html +++ b/docs/devices/devices_template.html @@ -209,7 +209,7 @@

Discover the extensive catalog of Bluetooth devices compatible with Theengs ecosystem, including our MQTT Gateway, Web Parser, - and OpenMQTTGateway. BLE trackers from Tile, Nut, TagIt, iTag, Gigaset G-Tag and the TicWatch GTH (Pro) will also be recognised and published as device trackers. The table also indicates whether each device has been confirmed to work with our [mobile application](https://app.theengs.io/).

+ and OpenMQTTGateway. BLE trackers from Tile, Nut, TagIt, iTAG, Gigaset G-Tag and the TicWatch GTH (Pro) will also be recognised and published as device trackers. The table also indicates whether each device has been confirmed to work with our [mobile application](https://app.theengs.io/).

{table_content_to_replace}

Note

All product and company names are trademarks or registered trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by or of them.

diff --git a/src/decoder.cpp b/src/decoder.cpp index 697f1a1b..b08e146c 100644 --- a/src/decoder.cpp +++ b/src/decoder.cpp @@ -651,6 +651,7 @@ int TheengsDecoder::decodeBLEJson(JsonObject& jsondata) { /* use a double for all values and cast later if required */ double temp_val; static double cal_val = 0; + std::string proc_str = ""; if (data_index_is_valid(src, decoder[2].as(), decoder[3].as())) { decoder_function dec_fun = &TheengsDecoder::value_from_hex_string; @@ -751,7 +752,15 @@ int TheengsDecoder::decodeBLEJson(JsonObject& jsondata) { } } else if (strncmp(post_proc[i].as(), "abs", 3) == 0) { temp_val = abs(temp_val); - } + } else if (strncmp(post_proc[i].as(), "SBBT-dir", 8) == 0) { // "SBBT" decoder specific post_proc + if (temp_val < 0) { + proc_str = "down"; + } else if (temp_val > 0) { + proc_str = "up"; + } else { + proc_str = "—"; + } + } } } } @@ -776,6 +785,11 @@ int TheengsDecoder::decodeBLEJson(JsonObject& jsondata) { jsondata[_key] = temp_val; } + /* _key as string if proc_str != "" */ + if (proc_str != "") { + jsondata[_key] = proc_str; + } + /* If the property is temp in C, make sure to convert and add temp in F */ if (_key.find("tempc", 0, 5) != std::string::npos) { double tc = jsondata[_key]; diff --git a/src/decoder.h b/src/decoder.h index 9e1c0c9b..d2482921 100644 --- a/src/decoder.h +++ b/src/decoder.h @@ -95,6 +95,7 @@ class TheengsDecoder { INODEEM, RUUVITAG_RAWV1, RUUVITAG_RAWV2, + SBBT, SBCS, SBCU, SBMS, diff --git a/src/devices.h b/src/devices.h index 78941ff9..ab00d93a 100644 --- a/src/devices.h +++ b/src/devices.h @@ -60,6 +60,7 @@ #include "devices/RDL52832_json.h" #include "devices/RuuviTag_RAWv1_json.h" #include "devices/RuuviTag_RAWv2_json.h" +#include "devices/SBBT_json.h" #include "devices/SBCS_json.h" #include "devices/SBCU_json.h" #include "devices/SBMS_json.h" @@ -164,6 +165,7 @@ const char* _devices[][2] = { {_iNodeEM_json, _iNodeEM_json_props}, {_RuuviTag_RAWv1_json, _RuuviTag_RAWv1_json_props}, {_RuuviTag_RAWv2_json, _RuuviTag_RAWv2_json_props}, + {_SBBT_json, _SBBT_json_props}, {_SBCS_json, _SBCS_json_props}, {_SBCU_json, _SBCU_json_props}, {_SBMS_json, _SBMS_json_props}, diff --git a/src/devices/SBBT_json.h b/src/devices/SBBT_json.h new file mode 100644 index 00000000..1c643ac2 --- /dev/null +++ b/src/devices/SBBT_json.h @@ -0,0 +1,70 @@ +const char* _SBBT_json = "{\"brand\":\"SwitchBot\",\"model\":\"Blind Tilt\",\"model_id\":\"W270160X\",\"tag\":\"0d02\",\"condition\":[\"uuid\",\"index\",0,\"0d00\",\"|\",\"uuid\",\"index\",0,\"fd3d\",\"&\",\"servicedata\",\"=\",6,\"index\",0,\"78\",\"&\",\"manufacturerdata\",\"=\",24,\"index\",0,\"6909\"],\"properties\":{\"open\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",20,2,false,false],\"post_proc\":[\"&\",127,\"-\",50,\"*\",2,\"±\",100,\"abs\"]},\"direction\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",20,2,false,false],\"post_proc\":[\"&\",127,\"-\",50,\"*\",2,\"SBBT-dir\"]},\"motion\":{\"decoder\":[\"bit_static_value\",\"manufacturerdata\",20,3,false,true]},\"calibrated\":{\"decoder\":[\"bit_static_value\",\"manufacturerdata\",19,0,false,true]},\"lightlevel\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",18,1,false,false]},\"batt\":{\"decoder\":[\"value_from_hex_data\",\"servicedata\",4,2,false,false],\"post_proc\":[\"&\",127]},\"mac\":{\"decoder\":[\"mac_from_hex_data\",\"manufacturerdata\",4]}}}"; +/*R""""( +{ + "brand":"SwitchBot", + "model":"Blind Tilt", + "model_id":"W270160X", + "tag":"0d02", + "condition":["uuid", "index", 0, "0d00", "|", "uuid", "index", 0, "fd3d", "&", "servicedata", "=", 6, "index", 0, "78", "&", "manufacturerdata", "=", 24, "index", 0, "6909"], + "properties":{ + "open":{ + "decoder":["value_from_hex_data", "manufacturerdata", 20, 2, false, false], + "post_proc":["&", 127, "-", 50, "*", 2, "±", 100, "abs"] + }, + "direction":{ + "decoder":["value_from_hex_data", "manufacturerdata", 20, 2, false, false], + "post_proc":["&", 127, "-", 50, "*", 2, "SBBT-dir"] + }, + "motion":{ + "decoder":["bit_static_value", "manufacturerdata", 20, 3, false, true] + }, + "calibrated":{ + "decoder":["bit_static_value", "manufacturerdata", 19, 0, false, true] + }, + "lightlevel":{ + "decoder":["value_from_hex_data", "manufacturerdata", 18, 1, false, false] + }, + "batt":{ + "decoder":["value_from_hex_data", "servicedata", 4, 2, false, false], + "post_proc":["&", 127] + }, + "mac":{ + "decoder":["mac_from_hex_data", "manufacturerdata", 4] + } + } +})"""";*/ + +const char* _SBBT_json_props = "{\"properties\":{\"open\":{\"unit\":\"%\",\"name\":\"open\"},\"direction\":{\"unit\":\"string\",\"name\":\"direction\"},\"motion\":{\"unit\":\"status\",\"name\":\"motion\"},\"calibrated\":{\"unit\":\"status\",\"name\":\"calibrated\"},\"lightlevel\":{\"unit\":\"int\",\"name\":\"light level\"},\"batt\":{\"unit\":\"%\",\"name\":\"battery\"},\"mac\":{\"unit\":\"string\",\"name\":\"MAC address\"}}}"; +/*R""""( +{ + "properties":{ + "open":{ + "unit":"%", + "name":"open" + }, + "direction":{ + "unit":"string", + "name":"direction" + }, + "motion":{ + "unit":"status", + "name":"motion" + }, + "calibrated":{ + "unit":"status", + "name":"calibrated" + }, + "lightlevel":{ + "unit":"int", + "name":"light level" + }, + "batt":{ + "unit":"%", + "name":"battery" + }, + "mac":{ + "unit":"string", + "name":"MAC address" + } + } +})"""";*/ diff --git a/tests/BLE/test_ble.cpp b/tests/BLE/test_ble.cpp index f1fe433b..36779750 100644 --- a/tests/BLE/test_ble.cpp +++ b/tests/BLE/test_ble.cpp @@ -169,6 +169,14 @@ const char* expected_name_uuid_mfgsvcdata[] = { "{\"brand\":\"Sensor Easy\",\"model\":\"SE RHT\",\"model_id\":\"SE_RHT\",\"type\":\"THB\",\"hum\":47,\"volt\":3.097}", "{\"brand\":\"Sensor Easy\",\"model\":\"SE TEMP PROBE\",\"model_id\":\"SE_TPROBE\",\"type\":\"THB\",\"tempc\":20.6,\"tempf\":69.08,\"volt\":3.044}", "{\"brand\":\"Sensor Easy\",\"model\":\"SE MAG\",\"model_id\":\"SE_MAG\",\"type\":\"CTMO\",\"cont\":true,\"open\":false,\"volt\":3.079}", + "{\"brand\":\"SwitchBot\",\"model\":\"Blind Tilt\",\"model_id\":\"W270160X\",\"type\":\"WCVR\",\"acts\":true,\"open\":30,\"direction\":\"up\",\"motion\":false,\"calibrated\":true,\"lightlevel\":2,\"batt\":60,\"mac\":\"AA:BB:CC:DD:EE:FF\"}", + "{\"brand\":\"SwitchBot\",\"model\":\"Blind Tilt\",\"model_id\":\"W270160X\",\"type\":\"WCVR\",\"acts\":true,\"open\":0,\"direction\":\"up\",\"motion\":false,\"calibrated\":true,\"lightlevel\":2,\"batt\":72,\"mac\":\"AA:BB:CC:DD:EE:FF\"}", + "{\"brand\":\"SwitchBot\",\"model\":\"Blind Tilt\",\"model_id\":\"W270160X\",\"type\":\"WCVR\",\"acts\":true,\"open\":100,\"direction\":\"—\",\"motion\":false,\"calibrated\":true,\"lightlevel\":2,\"batt\":54,\"mac\":\"AA:BB:CC:DD:EE:FF\"}", + "{\"brand\":\"SwitchBot\",\"model\":\"Blind Tilt\",\"model_id\":\"W270160X\",\"type\":\"WCVR\",\"acts\":true,\"open\":0,\"direction\":\"down\",\"motion\":false,\"calibrated\":true,\"lightlevel\":2,\"batt\":54,\"mac\":\"AA:BB:CC:DD:EE:FF\"}", + "{\"brand\":\"SwitchBot\",\"model\":\"Blind Tilt\",\"model_id\":\"W270160X\",\"type\":\"WCVR\",\"acts\":true,\"open\":46,\"direction\":\"up\",\"motion\":false,\"calibrated\":true,\"lightlevel\":2,\"batt\":54,\"mac\":\"AA:BB:CC:DD:EE:FF\"}", + "{\"brand\":\"SwitchBot\",\"model\":\"Blind Tilt\",\"model_id\":\"W270160X\",\"type\":\"WCVR\",\"acts\":true,\"open\":54,\"direction\":\"up\",\"motion\":false,\"calibrated\":true,\"lightlevel\":2,\"batt\":54,\"mac\":\"AA:BB:CC:DD:EE:FF\"}", + "{\"brand\":\"SwitchBot\",\"model\":\"Blind Tilt\",\"model_id\":\"W270160X\",\"type\":\"WCVR\",\"acts\":true,\"open\":80,\"direction\":\"down\",\"motion\":false,\"calibrated\":true,\"lightlevel\":2,\"batt\":96,\"mac\":\"AA:BB:CC:DD:EE:FF\"}", + "{\"brand\":\"SwitchBot\",\"model\":\"Blind Tilt\",\"model_id\":\"W270160X\",\"type\":\"WCVR\",\"acts\":true,\"open\":80,\"direction\":\"up\",\"motion\":false,\"calibrated\":true,\"lightlevel\":2,\"batt\":96,\"mac\":\"AA:BB:CC:DD:EE:FF\"}", }; const char* expected_name_mac_uuid_mfgsvcdata[] = { @@ -715,6 +723,14 @@ const char* test_name_uuid_mfgsvcdata[][5] = { {"SE RHT volt","P RHT 88888B","0x2a6f","5707f2190c","2f"}, {"SE TEMP PROBE","P TPROBE 000000","0x2a6e","5707f2e40b","0c08"}, {"SE MAG","P MAG CCCCCC","0x2a06","5707f2070c","3b00"}, + {"Switchbot_BlindTilt", "WoBlindTilt", "0xfd3d", "6909aabbccddeeff0d275514", "78003c"}, + {"Switchbot_BlindTilt", "WoBlindTilt", "0xfd3d", "6909aabbccddeeffd5256414", "780048"}, + {"Switchbot_BlindTilt", "WoBlindTilt", "0xfd3d", "6909aabbccddeeffd8253214", "780036"}, + {"Switchbot_BlindTilt", "WoBlindTilt", "0xfd3d", "6909aabbccddeeffcf270014", "780036"}, + {"Switchbot_BlindTilt", "WoBlindTilt", "0xfd3d", "6909aabbccddeeffe0254d14", "780036"}, + {"Switchbot_BlindTilt", "WoBlindTilt", "0xfd3d", "6909aabbccddeeffd3274914", "780036"}, + {"Switchbot_BlindTilt", "WoBlindTilt", "0xfd3d", "6909aabbccddeeffd3272814", "780060"}, + {"Switchbot_BlindTilt", "WoBlindTilt", "0xfd3d", "6909aabbccddeeffd3273c14", "780060"}, }; TheengsDecoder::BLE_ID_NUM test_name_uuid_mfgsvcdata_id_num[]{ @@ -731,6 +747,14 @@ TheengsDecoder::BLE_ID_NUM test_name_uuid_mfgsvcdata_id_num[]{ TheengsDecoder::BLE_ID_NUM::SE_RHT, TheengsDecoder::BLE_ID_NUM::SE_TPROBE, TheengsDecoder::BLE_ID_NUM::SE_MAG, + TheengsDecoder::BLE_ID_NUM::SBBT, + TheengsDecoder::BLE_ID_NUM::SBBT, + TheengsDecoder::BLE_ID_NUM::SBBT, + TheengsDecoder::BLE_ID_NUM::SBBT, + TheengsDecoder::BLE_ID_NUM::SBBT, + TheengsDecoder::BLE_ID_NUM::SBBT, + TheengsDecoder::BLE_ID_NUM::SBBT, + TheengsDecoder::BLE_ID_NUM::SBBT, }; // uuid test input [test name] [mac] [device name] [uuid] [manufacturer data] [service data]