Created
August 26, 2018 23:53
-
-
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
This file contains 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
// 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