Skip to content

Instantly share code, notes, and snippets.

@loginov-rocks
Created August 26, 2018 23:53
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 loginov-rocks/f918a2b11b98d20808a12a8c923e74bc to your computer and use it in GitHub Desktop.
Save loginov-rocks/f918a2b11b98d20808a12a8c923e74bc to your computer and use it in GitHub Desktop.
How to make a web app for your own Bluetooth Low Energy device? Step 5
// Selected device object cache
let deviceCache = null;
// Launch Bluetooth device chooser and connect to the selected
function connect() {
return (deviceCache ? Promise.resolve(deviceCache) :
requestBluetoothDevice()).
then(device => connectDeviceAndCacheCharacteristic(device)).
then(characteristic => startNotifications(characteristic)).
catch(error => log(error));
}
function requestBluetoothDevice() {
//
}
// Connect to the device specified, get service and characteristic
function connectDeviceAndCacheCharacteristic(device) {
//
}
// Enable the characteristic changes notification
function startNotifications(characteristic) {
//
}
// Output to terminal
function log(data, type = '') {
//
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment