Skip to content

Instantly share code, notes, and snippets.

@xanderificnl
Created July 22, 2023 01:26
Show Gist options
  • Save xanderificnl/c1416608cad708bc6c82010871fa4559 to your computer and use it in GitHub Desktop.
Save xanderificnl/c1416608cad708bc6c82010871fa4559 to your computer and use it in GitHub Desktop.
Switchbot - meter plus (via https://github.com/shmuelzon/esp32-ble2mqtt)
{
"network": {
"wifi": {
"ssid": "XiFi",
"password": ""
}
},
"mqtt": {
"server": {
"host": "192.168.88.253",
"port": 1883
},
"publish": {
"retain": true
},
"topics": {
"prefix": "BLE/",
"get_suffix": "/Get",
"set_suffix": "/Set"
}
},
"ble": {
"whitelist": [
"C6:C7:52:66:3C:BF"
],
"services": {
"definitions": {
"CBA20D00-224D-11E6-9FB8-0002A5D5C51B": {
"name": "SwitchBot"
}
}
},
"characteristics": {
"definitions": {
"CBA20002-224D-11E6-9FB8-0002A5D5C51B": {
"name": "Request"
},
"CBA20003-224D-11E6-9FB8-0002A5D5C51B": {
"name": "Response"
}
}
}
},
"log": {
"host": "224.0.0.200",
"port": 5000
}
}

Publish 87,15,49 to topic BLE/c6:c7:52:66:3c:bf/SwitchBot/Request/Set Subscribe to topic BLE/c6:c7:52:66:3c:bf/SwitchBot/Request/Request and parse. Sample code in JS below.

let response = "1,4,150,51"
let [a, b, c, d] = response.split(",")
// console.log(c *= -1)
if (c <= 128) {
c *= -1
b *= -1
} else {
c -= 128
}
temp = c + b;
console.log(`temp: ${c}.${b}c - ${d}%`);
//> "temp: 22.4c - 51%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment