BTHome formatted BLE Advertisements for MicroPython aioble #16999
Replies: 4 comments 2 replies
-
Thanks for documenting this @DavesCodeMusings ! Probably others will come along and want like this at some point :) |
Beta Was this translation helpful? Give feedback.
-
Hah! And to think I was creatively using SSID names containing sensor data in AP mode for this kind of thing … |
Beta Was this translation helpful? Give feedback.
-
I was very excited to see how open and well documented the BTHome format is. And the purchase of the UUID by Allterco Robotics (Shelly devices) for use by all was a pleasant surprise. The trick was digging into the MicroPython I've also made a few tweaks to my sample code that I'll get pushed to the repo soon. I've cleaned some things up and I'm now using Things are looking good in both nRF Connect and in Home Assistant. I can see my mocked up temperature, humidity, and battery percentage. Now to wire up some actual sensors! |
Beta Was this translation helpful? Give feedback.
-
That's really neat, great work! I personally think this would be a really helpful example to add to https://github.com/micropython/micropython-lib/tree/master/micropython/bluetooth/aioble/examples though I wouldn't want to lose the rest of the helpful details / context you've got in the readme... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Cue Sally Struthers late night TV advert voice...
"Do you want to broadcast sensor data over Bluetooth Low Energy advertisements using MicroPython? Sure, we all do."
I know I've wanted to do this for a while. Yes, there are consumer products that can have their firmware reflashed, but I've never found a way to DIY something from the ground up.
I wanted something that could broadcast data in advertisements (like a beacon) instead of the usual route of connecting and reading GATT characteristics. The part I could never get past was how to broadcast that data in an open format. In other words, not impersonating some other company's proprietary BLE advertisement to be able to read it in my home automation system.
It turns out the creators of BTHome wanted to do the same thing. And they're very willing to share what they know. But, the only examples I could find were C++.
Fortunately, BTHome has provided the details of their data format along with a service UUID that's available for anyone to use.
So with a little toil on a cold and rainy day, I give you the BTHome MicroPython module.
You can use it to build that DIY sensor beacon you've always wanted.
The project README has more details. And below you can see a screenshot of a BLE scan showing the sensor and the data being communicated in the advertisement. I mocked up the sensor readings with the same vaules as the BTHome format examples, so it should be easy to follow.
The yellow underlined bit is a hexadecimal representation containing the device information flags (40), temperature (02C409), and humidity (03BF13) in all their little endian, fixed-point decimal glory.
Beta Was this translation helpful? Give feedback.
All reactions