Last active
June 13, 2018 02:24
-
-
Save tylergets/3ef4abb9950a56e0e01415db0ac11e39 to your computer and use it in GitHub Desktop.
Web BLE Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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