Skip to content

Instantly share code, notes, and snippets.

@moritzmhmk
Last active September 2, 2023 12:26
Show Gist options
  • Save moritzmhmk/3c82e00b8cdbb8bdbe827e401ab91eb3 to your computer and use it in GitHub Desktop.
Save moritzmhmk/3c82e00b8cdbb8bdbe827e401ab91eb3 to your computer and use it in GitHub Desktop.
Read SwitchBot Indoor/Outdoor Thermo-Hygrometer
const noble = require('@abandonware/noble');
noble.on('stateChange', async (state) => {
if (state === 'poweredOn') {
await noble.startScanningAsync([], false);
}
});
noble.on('discover', async (peripheral) => {
if (peripheral.address !== "d5:c4:31:13:41:98") return
await noble.stopScanningAsync();
console.log(`${peripheral.address} (${peripheral.advertisement.localName})`);
console.log(peripheral);
data = peripheral.advertisement.manufacturerData
console.log(data)
// https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md#outdoor-temperaturehumidity-sensor
temp = ((data[10] & 0x0F) * 0.1 + (data[11] & 0x7F)) * ((data[11] & 0x80) > 0 ? 1 : -1);
humidity = data[12] & 0x7F;
console.log(temp, humidity)
serviceData = peripheral.advertisement.serviceData[0]
console.log(serviceData)
battery_pct = serviceData.data[2] & 0x7f // this is undocumented?
console.log(battery_pct)
process.exit(0);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment