- From: François Beaufort 🇫🇷 <fbeaufort@google.com>
- Date: Tue, 2 Feb 2016 11:03:47 +0100
- To: public-web-bluetooth <public-web-bluetooth@w3.org>
- Message-ID: <CAPpwU5JmTbsxU5oHqot5KmVbBHgwnGivPpR-3mTvUvfm3M+Btw@mail.gmail.com>
I wanted to let you know that I've just updated the <platinum-bluetooth> elements - a set of Polymer elements to discover and communicate with nearby Bluetooth devices thanks to experimental Web Bluetooth API. You can learn how to use them at https://elements.polymer-project.org/elements/platinum-bluetooth In the mean time, here's how to read the battery level from a nearby Bluetooth device advertising Battery service in HTML/JS: <platinum-bluetooth-device services-filter='["battery_service"]'> <platinum-bluetooth-service service='battery_service'> <platinum-bluetooth-characteristic characteristic='battery_level'> </platinum-bluetooth-characteristic> </platinum-bluetooth-service> </platinum-bluetooth-device> <script> var bluetoothDevice = document.querySelector('platinum-bluetooth-device'); var batteryLevel = document.querySelector('platinum-bluetooth-characteristic'); button.addEventListener('click', function() { bluetoothDevice.request().then(function() { return batteryLevel.read().then(function(value) { console.log('Battery Level is ' + value.getUint8(0) + '%'); }); }) .catch(function(error) { }); }); </script>
Received on Tuesday, 2 February 2016 10:04:17 UTC