<bt-device> and Renderless Web Components
steele.blue·291w
Preview
Report Post

May 4, 2020

I keep buying dumb Bluetooth devices and hooking them up to websites, but there’s just enough boilerplate to make integrating them a hassle. So, I made a little Custom Element to help automate some of the boilerplate.

You’d use <bt-device> like any other HTML element:

<!-- Connects to a Thermos Smart Lid water bottle -->
<bt-device
service="40fc0000-8a8d-4a32-a455-c1148e24a9f1"
characteristic="40fc0001-8a8d-4a32-a455-c1148e24a9f1"
notifications="true"
></bt-device>

And then grab the element and connect up to receive notifications:

const device = document.querySelector('bt-device');
await device.connect();
device.addEventListener('data', evt => {
console.log(evt.detai...

Similar Posts

Loading similar posts...