Skip to content

Instantly share code, notes, and snippets.

@tylergets
Last active June 13, 2018 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylergets/3ef4abb9950a56e0e01415db0ac11e39 to your computer and use it in GitHub Desktop.
Save tylergets/3ef4abb9950a56e0e01415db0ac11e39 to your computer and use it in GitHub Desktop.
Web BLE Demo
startDemo() {
let JUMPER_SERVICE = "cdeacb80-5235-4c07-8846-93a37ee6b86d";
let JUMPER_CHARACTERISTIC = "cdeacb81-5235-4c07-8846-93a37ee6b86d";
navigator.bluetooth.requestDevice({filters: [{services: [JUMPER_SERVICE]}]})
.then(device => device.gatt.connect())
.then(server => {
console.log('Connected to device');
return server.getPrimaryService(JUMPER_SERVICE);
})
.then(service => service.getCharacteristic(JUMPER_CHARACTERISTIC))
.then(characteristic => characteristic.startNotifications())
.then(characteristic => {
characteristic.addEventListener('characteristicvaluechanged', handleCharacteristicValueChanged);
console.log('Notifications have been started.');
})
.catch(error => {
console.log(error);
});
function handleCharacteristicValueChanged(event) {
var value = event.target.value;
console.log(value);
}
}
if (value.getUint8(0) == '129') {
console.log(value.getUint8(1) + ',' + value.getUint8(2) + ',' + value.getUint8(3));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment