From 6942795acfbc721e4a8cfc5691a539d800bf8386 Mon Sep 17 00:00:00 2001 From: DigiH <17110652+DigiH@users.noreply.github.com> Date: Tue, 26 Nov 2024 11:47:00 +0100 Subject: [PATCH] SwitchBot Meter Pro (CO2) decoder SwitchBot Meter Pro (CO2) initial decoder --- docs/devices/SBMP.md | 12 ++++++++ src/decoder.h | 1 + src/devices.h | 2 ++ src/devices/SBMP_json.h | 68 +++++++++++++++++++++++++++++++++++++++++ tests/BLE/test_ble.cpp | 3 ++ 5 files changed, 86 insertions(+) create mode 100644 docs/devices/SBMP.md create mode 100644 src/devices/SBMP_json.h diff --git a/docs/devices/SBMP.md b/docs/devices/SBMP.md new file mode 100644 index 000000000..2fd86814a --- /dev/null +++ b/docs/devices/SBMP.md @@ -0,0 +1,12 @@ +# SwitchBot Meter Pro (CO2) + +|Model Id|[W490001X](https://github.com/theengs/decoder/blob/development/src/devices/SBMP_json.h)| +|-|-| +|Brand|SwitchBot| +|Model|Meter Pro (CO2)| +|Short Description|Thermo-Hygrometer and CO2 Monitor| +|Communication|BLE broadcast| +|Frequency|2.4Ghz| +|Power Source|2 AA| +|Exchanged Data|temperature, humidity, carbon dioxide, battery| +|Encrypted|No| diff --git a/src/decoder.h b/src/decoder.h index 7a46eb91d..4a71d8ce8 100644 --- a/src/decoder.h +++ b/src/decoder.h @@ -101,6 +101,7 @@ class TheengsDecoder { SBMS, SBMT, SBMT_M, + SBMP, SBOT, SBOT_M, SBOT_S, diff --git a/src/devices.h b/src/devices.h index d982479d3..d28f2c45e 100644 --- a/src/devices.h +++ b/src/devices.h @@ -66,6 +66,7 @@ #include "devices/SBCU_json.h" #include "devices/SBMS_json.h" #include "devices/SBMT_json.h" +#include "devices/SBMP_json.h" #include "devices/SBOT_json.h" #include "devices/SBS1_json.h" #include "devices/SHT4X_json.h" @@ -179,6 +180,7 @@ const char* _devices[][2] = { {_SBMS_json, _SBMS_json_props}, {_SBMT_json, _SBMT_json_props}, {_SBMT_json_M, _SBMT_json_props}, + {_SBMP_json, _SBMP_json_props}, {_SBOT_json, _SBOT_json_props}, {_SBOT_json_M, _SBOT_json_props}, {_SBOT_json_S, _SBOT_json_props}, diff --git a/src/devices/SBMP_json.h b/src/devices/SBMP_json.h new file mode 100644 index 000000000..778a5e8fa --- /dev/null +++ b/src/devices/SBMP_json.h @@ -0,0 +1,68 @@ +#include "common_props.h" + +const char* _SBMP_json = "{\"brand\":\"SwitchBot\",\"model\":\"Meter Pro (CO2)\",\"model_id\":\"W490001X\",\"tag\":\"0f02\",\"condition\":[\"uuid\",\"index\",0,\"fd3d\",\"&\",\"servicedata\",\"=\",6,\"index\",0,\"35\",\"&\",\"manufacturerdata\",\"=\",36,\"index\",0,\"6909\"],\"properties\":{\".cal\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",21,1,false,false],\"post_proc\":[\"/\",10]},\"tempc\":{\"condition\":[\"manufacturerdata\",22,\"bit\",3,0],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",22,2,true,false],\"post_proc\":[\"+\",\".cal\",\"*\",-1]},\"_tempc\":{\"condition\":[\"manufacturerdata\",22,\"bit\",3,1],\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",22,2,true,false],\"post_proc\":[\"+\",\".cal\",\"-\",128]},\"hum\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",24,2,false,false],\"post_proc\":[\"&\",127]},\"co2\":{\"decoder\":[\"value_from_hex_data\",\"manufacturerdata\",30,4,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":"Meter Pro (CO2)", + "model_id":"W490001X", + "tag":"0f02", + "condition":["uuid", "index", 0, "fd3d", "&", "servicedata", "=", 6, "index", 0, "35", "&", "manufacturerdata", "=", 36, "index", 0, "6909"], + "properties":{ + ".cal":{ + "decoder":["value_from_hex_data", "manufacturerdata", 21, 1, false, false], + "post_proc":["/", 10] + }, + "tempc":{ + "condition":["manufacturerdata", 22, "bit", 3, 0], + "decoder":["value_from_hex_data", "manufacturerdata", 22, 2, true, false], + "post_proc":["+", ".cal", "*", -1] + }, + "_tempc":{ + "condition":["manufacturerdata", 22, "bit", 3, 1], + "decoder":["value_from_hex_data", "manufacturerdata", 22, 2, true, false], + "post_proc":["+", ".cal", "-", 128] + }, + "hum":{ + "decoder":["value_from_hex_data", "manufacturerdata", 24, 2, false, false], + "post_proc":["&", 127] + }, + "co2":{ + "decoder":["value_from_hex_data", "manufacturerdata", 30, 4, 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* _SBMP_json_props = "{\"properties\":{\"tempc\":{\"unit\":\"°C\",\"name\":\"temperature\"},\"hum\":{\"unit\":\"%\",\"name\":\"humidity\"},\"co2\":{\"unit\":\"ppm\",\"name\":\"carbon_dioxide\"},\"batt\":{\"unit\":\"%\",\"name\":\"battery\"},\"mac\":{\"unit\":\"string\",\"name\":\"MAC address\"}}}"; +/*R""""( +{ + "properties":{ + "tempc":{ + "unit":"°C", + "name":"temperature" + }, + "hum":{ + "unit":"%", + "name":"humidity" + }, + "co2":{ + "unit":"ppm", + "name":"carbon_dioxide" + }, + "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 b26c64fdc..50a152134 100644 --- a/tests/BLE/test_ble.cpp +++ b/tests/BLE/test_ble.cpp @@ -212,6 +212,7 @@ const char* expected_name_uuid_mfgsvcdata[] = { "{\"brand\":\"SwitchBot\",\"model\":\"Blind Tilt\",\"model_id\":\"W270160X\",\"type\":\"WCVR\",\"acts\":true,\"ctrl\":true,\"open\":70,\"direction\":\"up\",\"motion\":false,\"calibrated\":true,\"lightlevel\":2,\"batt\":100,\"mac\":\"AA:BB:CC:DD:EE:FF\"}", "{\"brand\":\"SwitchBot\",\"model\":\"Blind Tilt\",\"model_id\":\"W270160X\",\"type\":\"WCVR\",\"acts\":true,\"ctrl\":true,\"open\":50,\"direction\":\"up\",\"motion\":false,\"calibrated\":true,\"lightlevel\":2,\"batt\":100,\"mac\":\"AA:BB:CC:DD:EE:FF\"}", "{\"brand\":\"nut\",\"model\":\"Smart Tracker\",\"model_id\":\"NUT\",\"type\":\"TRACK\",\"cidc\":false,\"acts\":true,\"track\":true,\"device\":\"nut Tracker\"}", + "{\"brand\":\"SwitchBot\",\"model\":\"Meter Pro (CO2)\",\"model_id\":\"W490001X\",\"type\":\"AIR\",\"acts\":true,\"tempc\":22.8,\"tempf\":73.04,\"hum\":40,\"co2\":893,\"batt\":100,\"mac\":\"B0:E9:FE:DD:EE:FF\"}", }; const char* expected_name_mac_uuid_mfgsvcdata[] = { @@ -893,6 +894,7 @@ const char* test_name_uuid_mfgsvcdata[][5] = { {"Switchbot_BlindTilt NEW", "WoBlindTilt", "0xfd3d", "6909aabbccddeeff2427412184", "780064"}, {"Switchbot_BlindTilt NEW", "WoBlindTilt", "0xfd3d", "6909aabbccddeeff39274b4184", "780064"}, {"Nut","nut","0x180a","12345678",""}, + {"SwitchBot Meter Pro (CO2)", "Outdoor Meter", "0xfd3d", "6909b0e9feddeeff0ce40896280004037d00", "350064"}, }; TheengsDecoder::BLE_ID_NUM test_name_uuid_mfgsvcdata_id_num[]{ @@ -922,6 +924,7 @@ TheengsDecoder::BLE_ID_NUM test_name_uuid_mfgsvcdata_id_num[]{ TheengsDecoder::BLE_ID_NUM::SBBT, TheengsDecoder::BLE_ID_NUM::SBBT, TheengsDecoder::BLE_ID_NUM::NUT, + TheengsDecoder::BLE_ID_NUM::SBMP, }; // uuid test input [test name] [mac] [device name] [uuid] [manufacturer data] [service data]