Skip to content

Instantly share code, notes, and snippets.

@edwingustafson
Created January 6, 2019 23:20
Show Gist options
  • Save edwingustafson/8a53922135d549873154ea938d2de037 to your computer and use it in GitHub Desktop.
Save edwingustafson/8a53922135d549873154ea938d2de037 to your computer and use it in GitHub Desktop.
Web Bluetooth
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