Skip to content

Commit

Permalink
Detect battery level in LYWSD02 decoder (#146)
Browse files Browse the repository at this point in the history
* Detect battery percentage in LYWSD02 decoder

* Only check on product ID to dect LYWSD02
  • Loading branch information
koenvervloesem authored Jul 8, 2022
1 parent 6bc0595 commit 95b12b1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/devices/LYWSD02.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
|Communication|BLE broadcast|
|Frequency|2.4Ghz|
|Power source|2 CR2032|
|Exchanged data|humidity, temperature|
|Exchanged data|humidity, temperature, battery|
|Encrypted|No|
12 changes: 8 additions & 4 deletions src/devices/LYWSD02_json.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
#include "common_props.h"

const char* _LYWSD02_json = "{\"brand\":\"Xiaomi\",\"model\":\"Cleargrass clock\",\"model_id\":\"LYWSD02\",\"condition\":[\"servicedata\",\"index\",2,\"205b04\"],\"properties\":{\"tempc\":{\"condition\":[\"servicedata\",25,\"4\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",30,4,true],\"post_proc\":[\"/\",10]},\"hum\":{\"condition\":[\"servicedata\",25,\"6\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",30,4,true,false],\"post_proc\":[\"/\",10]}}}";
const char* _LYWSD02_json = "{\"brand\":\"Xiaomi\",\"model\":\"Cleargrass clock\",\"model_id\":\"LYWSD02\",\"condition\":[\"servicedata\",\"index\",4,\"5b04\"],\"properties\":{\"tempc\":{\"condition\":[\"servicedata\",24,\"0410\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",30,4,true],\"post_proc\":[\"/\",10]},\"hum\":{\"condition\":[\"servicedata\",24,\"0610\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",30,4,true,false],\"post_proc\":[\"/\",10]},\"batt\":{\"condition\":[\"servicedata\",24,\"0a10\"],\"decoder\":[\"value_from_hex_data\",\"servicedata\",30,2,false,false]}}}";
/* R""""(
{
"brand":"Xiaomi",
"model":"Cleargrass clock",
"model_id":"LYWSD02",
"condition":["servicedata", "index", 2, "205b04"],
"condition":["servicedata", "index", 4, "5b04"],
"properties":{
"tempc":{
"condition":["servicedata", 25, "4"],
"condition":["servicedata", 24, "0410"],
"decoder":["value_from_hex_data", "servicedata", 30, 4, true],
"post_proc":["/", 10]
},
"hum":{
"condition":["servicedata", 25, "6"],
"condition":["servicedata", 24, "0610"],
"decoder":["value_from_hex_data", "servicedata", 30, 4, true, false],
"post_proc":["/", 10]
},
"batt":{
"condition":["servicedata", 24, "0a10"],
"decoder":["value_from_hex_data", "servicedata", 30, 2, false, false]
}
}
})"""";*/
Expand Down
3 changes: 3 additions & 0 deletions tests/BLE/test_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const char* expected_servicedata[] = {
"{\"brand\":\"Xiaomi\",\"model\":\"Cleargrass clock\",\"model_id\":\"LYWSD02\",\"tempc\":25.6,\"tempf\":78.08}",
"{\"brand\":\"Xiaomi\",\"model\":\"Cleargrass clock\",\"model_id\":\"LYWSD02\",\"hum\":69}",
"{\"brand\":\"Xiaomi\",\"model\":\"Cleargrass clock\",\"model_id\":\"LYWSD02\",\"tempc\":26.5,\"tempf\":79.7}",
"{\"brand\":\"Xiaomi\",\"model\":\"Cleargrass clock\",\"model_id\":\"LYWSD02\",\"batt\":8}",
"{\"brand\":\"Xiaomi\",\"model\":\"Mi Jia round\",\"model_id\":\"LYWSDCGQ\",\"tempc\":26,\"tempf\":78.8,\"hum\":61.4}",
"{\"brand\":\"Xiaomi\",\"model\":\"Mi Jia round\",\"model_id\":\"LYWSDCGQ\",\"hum\":61.4}",
"{\"brand\":\"Xiaomi\",\"model\":\"Mi Jia round\",\"model_id\":\"LYWSDCGQ\",\"batt\":81}",
Expand Down Expand Up @@ -149,6 +150,7 @@ const char* test_servicedata[][2] = {
{"Cleargrass clock", "70205b04756ab883c8593f090410020001"},
{"Cleargrass clock", "70205b04dc6ab883c8593f09061002b202"},
{"Cleargrass clock", "70205b04756ab883c8593f090410020901"},
{"Cleargrass clock", "70205b04859638b1002ee7090a100108"},
{"Mi jia round sensor", "5020aa0137dfaa33342d580d100404016602"},
{"Mi jia round sensor", "5020aa018ddfaa33342d580610026602"},
{"Mi jia round sensor", "5020aa0155aabbccddeeff0a100151"},
Expand Down Expand Up @@ -193,6 +195,7 @@ TheengsDecoder::BLE_ID_NUM test_svcdata_id_num[]{
TheengsDecoder::BLE_ID_NUM::LYWSD02,
TheengsDecoder::BLE_ID_NUM::LYWSD02,
TheengsDecoder::BLE_ID_NUM::LYWSD02,
TheengsDecoder::BLE_ID_NUM::LYWSD02,
TheengsDecoder::BLE_ID_NUM::LYWSDCGQ,
TheengsDecoder::BLE_ID_NUM::LYWSDCGQ,
TheengsDecoder::BLE_ID_NUM::LYWSDCGQ,
Expand Down

0 comments on commit 95b12b1

Please sign in to comment.