webbluetooth
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -27,10 +27,4 @@ /* | ||
var bluetooth = require('../').bluetooth; | ||
var gattServer; | ||
var heartChar; | ||
function log(message) { | ||
console.log(message); | ||
} | ||
log('Requesting Bluetooth Devices...'); | ||
console.log('Requesting Bluetooth Devices...'); | ||
bluetooth.requestDevice({ | ||
@@ -40,43 +34,27 @@ filters:[{ services:[ "heart_rate" ] }] | ||
.then(device => { | ||
log('Found device: ' + device.name); | ||
console.log('Found device: ' + device.name); | ||
return device.gatt.connect(); | ||
}) | ||
.then(server => { | ||
gattServer = server; | ||
log('Gatt server connected: ' + gattServer.connected); | ||
return gattServer.getPrimaryService("heart_rate"); | ||
console.log('Gatt server connected: ' + server.connected); | ||
return server.getPrimaryService("heart_rate"); | ||
}) | ||
.then(service => { | ||
log('Primary service: ' + service.uuid); | ||
console.log('Primary service: ' + service.uuid); | ||
return service.getCharacteristic("heart_rate_measurement"); | ||
}) | ||
.then(characteristic => { | ||
log('Characteristic: ' + characteristic.uuid); | ||
heartChar = characteristic; | ||
return heartChar.getDescriptors(); | ||
console.log('Characteristic: ' + characteristic.uuid); | ||
return characteristic.startNotifications(); | ||
}) | ||
.then(descriptors => { | ||
descriptors.forEach(descriptor => { | ||
log('Descriptor: ' + descriptor.uuid); | ||
.then(characteristic => { | ||
console.log('Notifications started'); | ||
characteristic.addEventListener("characteristicvaluechanged", event => { | ||
if (event.value.buffer.byteLength) console.log(event.value.getUint16(0)); | ||
}); | ||
return Array.apply(null, Array(10)).reduce(sequence => { | ||
return sequence.then(() => { | ||
return heartChar.readValue(); | ||
}).then(value => { | ||
if (!value.buffer.byteLength) { | ||
return log('No value'); | ||
} | ||
log('Value: ' + value.getUint16(0)); | ||
}); | ||
}, Promise.resolve()); | ||
}) | ||
.then(() => { | ||
gattServer.disconnect(); | ||
log('Gatt server connected: ' + gattServer.connected); | ||
process.exit(); | ||
}) | ||
.catch(error => { | ||
log(error); | ||
console.log(error); | ||
process.exit(); | ||
}); |
{ | ||
"name": "webbluetooth", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Node.js implementation of the Web Bluetooth Specification", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/thegecko/webbluetooth", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1582877
6309