Skip to content

Commit

Permalink
SwitchBot Meter Pro (CO2) decoder (theengs#587)
Browse files Browse the repository at this point in the history
SwitchBot Meter Pro (CO2)  initial decoder
  • Loading branch information
DigiH authored Nov 27, 2024
1 parent c8fcf8a commit 0713619
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/devices/SBMP.md
Original file line number Diff line number Diff line change
@@ -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|
1 change: 1 addition & 0 deletions src/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class TheengsDecoder {
SBMS,
SBMT,
SBMT_M,
SBMP,
SBOT,
SBOT_M,
SBOT_S,
Expand Down
2 changes: 2 additions & 0 deletions src/devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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},
Expand Down
68 changes: 68 additions & 0 deletions src/devices/SBMP_json.h
Original file line number Diff line number Diff line change
@@ -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"
}
}
})"""";*/
3 changes: 3 additions & 0 deletions tests/BLE/test_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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[]{
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 0713619

Please sign in to comment.