functiononButtonClick(){'use strict';log('Requesting Bluetooth Device...');navigator.bluetooth.requestDevice({filters:[{services:['battery_service']}]}).then(device=>{log('> Found '+device.name);log('Connecting to GATT Server...');returndevice.gatt.connect();}).then(server=>{log('Getting Battery Service...');returnserver.getPrimaryService('battery_service');}).then(service=>{log('Getting Battery Level Characteristic...');returnservice.getCharacteristic('battery_level');}).then(characteristic=>{log('Reading Battery Level...');returncharacteristic.readValue();}).then(value=>{// In Chrome 50+, a DataView is returned instead of an ArrayBuffer.value=value.buffer?value:newDataView(value);letbatteryLevel=value.getUint8(0);log('> Battery Level is '+batteryLevel+'%');}).catch(error=>{log('Argh! '+error);});}