This document summarizes an introduction to the physical web and Bluetooth technologies. It discusses Bluetooth basics and how it can be used to broadcast URLs from devices to connect physical objects to web content. It also covers the Web Bluetooth API, which allows controlling Bluetooth devices from the web by reading and writing characteristic values. Code examples are provided to demonstrate broadcasting a URL using the Eddystone beacon format and reading heart rate data from a Bluetooth device using the Web Bluetooth API.
53. @joel__lord
#midwestjs
Web Bluetooth API
• When reading the value, it returns a ArrayBuffer which you need to
convert into an int value
navigator.bluetooth.requestDevice(options)
.then(device => device.gatt.connect())
.then(server => server.getPrimaryService('battery_service'))
.then(service => service.getCharacteristic('battery_level'))
.then(characteristic => characteristic.readValue())
.then(value => {
var intVal = value.getUint8(0);
console.log('Battery percentage is ' + intVal);
})
.catch(error => { console.log(error); });