by Carl Vuorinen / @cvuorinen
THE PRESENTER SHALL NOT BE LIABLE FOR ANY CUT FINGERS, LOST DRONES, BROKEN WINDOWS, OR ANY OTHER INCIDENTAL, INDIRECT, PUNITIVE, SPECIAL OR CONSEQUENTIAL DAMAGES WHATSOEVER ARISING OUT OF USAGE OF THESE CODE EXAMPLES OR THE PROGRESSIVE WEB APP WITHOUT PROPER SUPERVISION, EVEN IF THE PRESENTER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
navigator.bluetooth.requestDevice(options)
.then(device => { /* ... */ })
.catch(error => { console.log(error) })
navigator.bluetooth.requestDevice(options)
.then(device => device.gatt.connect())
.then(server => { /* ... */ })
.catch(error => { console.log(error) })
navigator.bluetooth.requestDevice(options)
.then(device => device.gatt.connect())
.then(server => server.getPrimaryService('battery_service'))
.then(service => { /* ... */ })
.catch(error => { console.log(error) })
navigator.bluetooth.requestDevice(options)
.then(device => device.gatt.connect())
.then(server => server.getPrimaryService('battery_service'))
.then(service => service.getCharacteristic('battery_level'))
.then(characteristic => { /* ... */ })
.catch(error => { console.log(error) })
Are we there yet?
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 => { /* ... */ })
.catch(error => { console.log(error) })
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 => {
console.log('Battery percentage is ' + value.getUint8(0))
})
.catch(error => { console.log(error) })
value comes in a DataView object (binary ArrayBuffer)
navigator.bluetooth.requestDevice(options)
.then(device => device.gatt.connect())
.then(server => server.getPrimaryService('heart_rate'))
.then(service => service.getCharacteristic('heart_rate_control_point'))
.then(characteristic => characteristic.writeValue(Uint8Array.of(1)))
.then(_ => {
console.log('Value has been written.')
})
.catch(error => { console.log(error) })
value comes in a DataView object (binary ArrayBuffer)
write('fa00', 'fa0b', [4, ++fa0b, 0, 4, 1, 0, 0x32, 0x30,
0x31, 0x34, 0x2D, 0x31, 0x30, 0x2D, 0x32, 0x38, 0x00]);
???