navigator.bluetooth.requestDevice({ filters: [{ services: ['battery_service'] }] })
.then(device => {
// Human-readable name of the device.
console.log(device.name);
// Indicates whether or not the device is paired with the system.
console.log(device.paired);
// Filtered UUIDs of GATT services the website origin has access to.
console.log(device.uuids);
// Attempts to connect to remote GATT Server.
return device.connectGATT();
})
.then(server => {...})
.catch(error => { console.log(error); });
Web Bluetooth API is at the time of writing partially implemented in Chrome OS M45 behind an experimental flag. [Once enabled] you should be able to scan for and connect to nearby Bluetooth devices and read/write Bluetooth characteristics.
In future releases you should also be able to subscribe to notifications and stuff like that.
Leave a comment