Skip to content

Commit

Permalink
Switchbot S1 status decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
DigiH committed Mar 17, 2022
1 parent 86c8400 commit 3802f37
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module.exports = {
'devices/CGPR1',
'devices/RuuviTag_RAWv1',
'devices/RuuviTag_RAWv2',
'devices/SBS1',
'devices/TPMS',
'devices/VEGTRUG',
'devices/WS02',
Expand Down
12 changes: 12 additions & 0 deletions docs/devices/SBS1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SwitchBot S1

|Model Id|[SWITCHBOT-S1](https://github.com/theengs/decoder/blob/development/src/devices/SBS1_json.h)|
|-|-|
|Brand|SwitchBot|
|Model|SwitchBot S1|
|Short Description|Switch Button Pusher|
|Communication|BLE broadcast|
|Frequency|2.4Ghz|
|Power source|1 CR2|
|Exchanged data|mode, state, battery|
|Encrypted|No|
1 change: 1 addition & 0 deletions src/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class TheengsDecoder {
IBT_2X,
RUUVITAG_RAWV1,
RUUVITAG_RAWV2,
SBS1,
BM_V23,
MS_CDP,
GAEN,
Expand Down
2 changes: 2 additions & 0 deletions src/devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "devices/Mokobeacon_json.h"
#include "devices/RuuviTag_RAWv1_json.h"
#include "devices/RuuviTag_RAWv2_json.h"
#include "devices/SBS1_json.h"
#include "devices/TPMS_json.h"
#include "devices/VEGTRUG_json.h"
#include "devices/WS02_json.h"
Expand Down Expand Up @@ -94,6 +95,7 @@ const char* _devices[][2] = {
{_IBT_2X_json, _IBT_2X_json_props},
{_RuuviTag_RAWv1_json, _RuuviTag_RAWv1_json_props},
{_RuuviTag_RAWv2_json, _RuuviTag_RAWv2_json_props},
{_SBS1_json, _SBS1_json_props},
{_BM_V23_json, _BM_V23_json_props},
{_MS_CDP_json, _MS_CDP_json_props},
{_GAEN_json, _GAEN_json_props},
Expand Down
54 changes: 54 additions & 0 deletions src/devices/SBS1_json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const char* _SBS1_json = "{\"brand\":\"SwitchBot\",\"model\":\"S1\",\"model_id\":\"SWITCHBOT-S1\",\"condition\":[\"uuid\",\"index\",0,\"0d00\",\"&\",\"servicedata\",\"=\",6,\"index\",0,\"48\"],\"properties\":{\"mode\":{\"condition\":[\"servicedata\",2,\"8\",\"|\",\"servicedata\",2,\"9\",\"|\",\"servicedata\",2,\"c\",\"|\",\"servicedata\",2,\"d\"],\"decoder\":[\"static_value\",\"on/off\"]},\"_mode\":{\"condition\":[\"servicedata\",2,\"0\",\"|\",\"servicedata\",2,\"1\",\"|\",\"servicedata\",2,\"4\",\"|\",\"servicedata\",2,\"5\"],\"decoder\":[\"static_value\",\"onestate\"]},\"state\":{\"condition\":[\"servicedata\",2,\"0\",\"|\",\"servicedata\",2,\"1\",\"|\",\"servicedata\",2,\"8\",\"|\",\"servicedata\",2,\"9\"],\"decoder\":[\"static_value\",\"on\"]},\"_state\":{\"condition\":[\"servicedata\",2,\"4\",\"|\",\"servicedata\",2,\"5\",\"|\",\"servicedata\",2,\"c\",\"|\",\"servicedata\",2,\"d\"],\"decoder\":[\"static_value\",\"off\"]},\"batt\":{\"condition\":[\"servicedata\",4,\"0\",\"|\",\"servicedata\",4,\"1\",\"|\",\"servicedata\",4,\"2\",\"|\",\"servicedata\",4,\"3\",\"|\",\"servicedata\",4,\"4\",\"|\",\"servicedata\",4,\"5\",\"|\",\"servicedata\",4,\"6\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",4,2,false,false]},\"_batt\":{\"condition\":[\"servicedata\",4,\"8\",\"|\",\"servicedata\",4,\"9\",\"|\",\"servicedata\",4,\"a\",\"|\",\"servicedata\",4,\"b\",\"|\",\"servicedata\",4,\"c\",\"|\",\"servicedata\",4,\"d\",\"|\",\"servicedata\",4,\"e\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",4,2,false,false],\"post_proc\":['-',128]}}}";
/*R""""(
{
"brand":"SwitchBot",
"model":"S1",
"model_id":"SWITCHBOT-S1",
"condition":["uuid", "index",0, "0d00","&", "servicedata", "=", 6, "index", 0, "48"],
"properties":{
"mode":{
"condition":["servicedata", 2, "8", "|", "servicedata", 2, "9", "|", "servicedata", 2, "c", "|", "servicedata", 2, "d"],
"decoder":["static_value", "on/off"]
},
"_mode":{
"condition":["servicedata", 2, "0", "|", "servicedata", 2, "1", "|", "servicedata", 2, "4", "|", "servicedata", 2, "5"],
"decoder":["static_value", "onestate"]
},
"state":{
"condition":["servicedata", 2, "0", "|", "servicedata", 2, "1", "|", "servicedata", 2, "8", "|", "servicedata", 2, "9"],
"decoder":["static_value", "on"]
},
"_state":{
"condition":["servicedata", 2, "4", "|", "servicedata", 2, "5", "|", "servicedata", 2, "c", "|", "servicedata", 2, "d"],
"decoder":["static_value", "off"]
},
"batt":{
"condition":["servicedata", 4, "0", "|", "servicedata", 4, "1", "|", "servicedata", 4, "2", "|", "servicedata", 4, "3", "|", "servicedata", 4, "4", "|", "servicedata", 4, "5", "|", "servicedata", 4, "6"],
"decoder":["value_from_hex_data", "servicedata", 4, 2, false, false]
},
"_batt":{
"condition":["servicedata", 4, "8", "|", "servicedata", 4, "9", "|", "servicedata", 4, "a", "|", "servicedata", 4, "b", "|", "servicedata", 4, "c", "|", "servicedata", 4, "d", "|", "servicedata", 4, "e"],
"decoder":["value_from_hex_data", "servicedata", 4, 2, false, false],
"post_proc":['-', 128]
}
}
})"""";*/

const char* _SBS1_json_props = "{\"properties\":{\"mode\":{\"unit\":\"string\",\"name\":\"mode\"},\"state\":{\"unit\":\"string\",\"name\":\"state\"},\"batt\":{\"unit\":\"%\",\"name\":\"battery\"}}}";
/*R""""(
{
"properties":{
"mode":{
"unit":"string",
"name":"mode"
},
"state":{
"unit":"string",
"name":"state"
},
"batt":{
"unit":"%",
"name":"battery"
}
}
})"""";*/
9 changes: 9 additions & 0 deletions tests/BLE/test_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ const char* expected_uuid[] = {
"{\"brand\":\"Mokosmart\",\"model\":\"Beacon\",\"model_id\":\"Mokobeacon\",\"batt\":100,\"x_axis\":-24576,\"y_axis\":-3841,\"z_axis\":-8189}",
"{\"brand\":\"Mokosmart\",\"model\":\"BeaconX Pro\",\"model_id\":\"MBXPRO\",\"tempc\":27.4,\"tempf\":81.32,\"hum\":49.4,\"volt\":3.247}",
"{\"brand\":\"GENERIC\",\"model\":\"GAEN\",\"model_id\":\"GAEN\",\"rpi\":\"e7c6d34c71e48baf278bd99be74685bc\",\"aem\":\"a78126ab\"}",
"{\"brand\":\"SwitchBot\",\"model\":\"S1\",\"model_id\":\"SWITCHBOT-S1\",\"mode\":\"on/off\",\"state\":\"off\",\"batt\":91}",
"{\"brand\":\"SwitchBot\",\"model\":\"S1\",\"model_id\":\"SWITCHBOT-S1\",\"mode\":\"on/off\",\"state\":\"on\",\"batt\":76}",
"{\"brand\":\"SwitchBot\",\"model\":\"S1\",\"model_id\":\"SWITCHBOT-S1\",\"mode\":\"onestate\",\"state\":\"on\",\"batt\":91}",
};

// Service data test input [test name] [data]
Expand Down Expand Up @@ -268,6 +271,9 @@ const char* test_uuid[][4] = {
{"Mokobeacon", "0xff01", "servicedata", "64000000005085a000f0ffe003"},
{"MokoXPro", "feab", "servicedata", "70000a011201ee0caf03def14635998a"},
{"GAEN", "fd6f", "servicedata", "e7c6d34c71e48baf278bd99be74685bca78126ab"},
{"Switchbot_S1", "0d00", "servicedata", "48d0db"},
{"Switchbot_S1", "0d00", "servicedata", "4890cc"},
{"Switchbot_S1", "0d00", "servicedata", "48005b"},
};

TheengsDecoder::BLE_ID_NUM test_uuid_id_num[]{
Expand Down Expand Up @@ -295,6 +301,9 @@ TheengsDecoder::BLE_ID_NUM test_uuid_id_num[]{
TheengsDecoder::BLE_ID_NUM::MOKOBEACON,
TheengsDecoder::BLE_ID_NUM::MOKOBEACONXPRO,
TheengsDecoder::BLE_ID_NUM::GAEN,
TheengsDecoder::BLE_ID_NUM::SBS1,
TheengsDecoder::BLE_ID_NUM::SBS1,
TheengsDecoder::BLE_ID_NUM::SBS1,
};

template <typename T>
Expand Down

0 comments on commit 3802f37

Please sign in to comment.