Created
January 6, 2019 23:20
-
-
Save edwingustafson/8a53922135d549873154ea938d2de037 to your computer and use it in GitHub Desktop.
Web Bluetooth
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
const serviceUuid = 0xFFE0, characteristicUuid = 0xFFE1; | |
document.addEventListener('DOMContentLoaded', () => { | |
document.getElementById('connect').addEventListener('click', (event) => { | |
event.target.style.display = 'none'; | |
navigator.bluetooth.requestDevice({ | |
filters: [{name: 'HMSoft', services: [serviceUuid]}], | |
}).then((device) => { | |
document.getElementById('form').style.display = 'block'; | |
device.gatt.connect(). | |
then((server) => server.getPrimaryService(serviceUuid)). | |
then((service) => service.getCharacteristic(characteristicUuid)). | |
then((characteristic) => characteristic.startNotifications(). | |
then(() => characteristic.addEventListener('characteristicvaluechanged', receive)) | |
) | |
; | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment