Created
October 10, 2017 03:57
-
-
Save scytacki/a675a1cc1fb28d8326a2127bb9a60ca8 to your computer and use it in GitHub Desktop.
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
device = // Step 1: ask for a device | |
await navigator.bluetooth.requestDevice({ | |
filters: [{ services: [tagIdentifier] }], | |
optionalServices: [serviceAddr] | |
}); | |
server = // Step 2: Connect to device | |
await device.gatt.connect(); | |
deviceConnected(server); | |
service = // Step 3: Get the Service | |
await server.getPrimaryService(serviceAddr); | |
enableChar = // Step 4: Enable Light Sensor | |
await service.getCharacteristic(enableAddr); | |
await enableChar.writeValue(new Uint8Array([0x01])); | |
valueChar = // Step 5: Get light characteristic | |
await service.getCharacteristic(valueAddr); | |
// Step 6: Loop every 600ms | |
readIntervalID = setInterval(async () => { | |
byteArray = // Step 7: Read bytes | |
await valueChar.readValue(); | |
// Step 8: display light | |
displayLight(byteArray.getUint16(0, true)); | |
},1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment