Closed beaufortfrancois closed 8 years ago
function readBatteryLevel() { services: ['battery_service'] }] }) - .then(function(device) { + .then(function (device) { return device.gatt.connect(); }) - .then(function(server) { + .then(function (server) { return server.getPrimaryService('battery_service'); }) - .then(function(service) { - if (!service) { - throw 'Battery Service not found'; - } + .then(function (service) { return service.getCharacteristic('battery_level'); }) .then(function (characteristic) { @@ -29,7 +26,7 @@ function readBatteryLevel() { .then(function (value) { $target.innerHTML = 'Battery percentage is <b>' + value.getUint8(0) + '</b>.'; }) - .catch(function(error) { + .catch(function (error) { $target.innerText = error; }); }
👍 Done.