Comparing version 0.0.2 to 0.0.3
100
index.js
@@ -1,99 +0,3 @@ | ||
var events = require('events'); | ||
var util = require('util'); | ||
var Noble = require('./lib/noble'); | ||
var bindings = require('./build/Release/binding.node'); | ||
var NobleBindings = bindings.Noble; | ||
inherits(NobleBindings, events.EventEmitter); | ||
// extend prototype | ||
function inherits(target, source) { | ||
for (var k in source.prototype) { | ||
target.prototype[k] = source.prototype[k]; | ||
} | ||
} | ||
function Noble() { | ||
this._bindings = new NobleBindings(); | ||
this._peripherals = {}; | ||
var self = this; | ||
this._bindings.on('stateChange', function(state) { | ||
self.emit('stateChange', state); | ||
}); | ||
this._bindings.on('scanStart', function(state) { | ||
self.emit('scanStart'); | ||
}); | ||
this._bindings.on('scanStop', function(state) { | ||
self.emit('scanStop'); | ||
}); | ||
this._bindings.on('peripheralDiscover', function(uuid, localName, services, rssi) { | ||
var peripheral = self._peripherals[uuid] = new NoblePeripheral(uuid, localName, services, rssi); | ||
self.emit('peripheralDiscover', peripheral); | ||
}); | ||
this._bindings.on('peripheralConnect', function(uuid) { | ||
var peripheral = self._peripherals[uuid]; | ||
self.emit('peripheralConnect', peripheral); | ||
peripheral.emit('connect'); | ||
}); | ||
this._bindings.on('peripheralConnectFailure', function(uuid, reason) { | ||
var peripheral = self._peripherals[uuid]; | ||
self.emit('peripheralConnectFailure', peripheral, reason); | ||
peripheral.emit('connectFailure', reason); | ||
}); | ||
this._bindings.on('peripheralDisonnect', function(uuid) { | ||
var peripheral = self._peripherals[uuid]; | ||
self.emit('peripheralDisconnect', peripheral); | ||
peripheral.emit('disconnect'); | ||
}); | ||
} | ||
util.inherits(Noble, events.EventEmitter); | ||
Noble.prototype.startScanning = function(serviceUUIDs, allowDuplicates) { | ||
this._bindings.startScanning(serviceUUIDs, allowDuplicates); | ||
}; | ||
Noble.prototype.stopScanning = function(serviceUUIDs, allowDuplicates) { | ||
this._bindings.stopScanning(); | ||
}; | ||
Noble.prototype.connectPeripheral = function(uuid) { | ||
this._bindings.connectPeripheral(uuid); | ||
}; | ||
Noble.prototype.disconnectPeripheral = function(uuid) { | ||
this._bindings.disconnectPeripheral(uuid); | ||
}; | ||
var noble = new Noble(); | ||
module.exports = noble; | ||
function NoblePeripheral(uuid, localName, services, rssi) { | ||
this.uuid = uuid; | ||
this.localName = localName; | ||
this.services = services; | ||
this.rssi = rssi; | ||
} | ||
util.inherits(NoblePeripheral, events.EventEmitter); | ||
NoblePeripheral.prototype.connect = function() { | ||
noble.connectPeripheral(this.uuid); | ||
}; | ||
NoblePeripheral.prototype.disconnect = function() { | ||
noble.disconnectPeripheral(this.uuid); | ||
}; | ||
module.exports = new Noble(); |
@@ -5,3 +5,3 @@ { | ||
"description": "A node.js BLE (Bluetooth low energy) library.", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"repository": { | ||
@@ -17,3 +17,4 @@ "type": "git", | ||
"BLE", | ||
"bluetooth low energy" | ||
"bluetooth low energy", | ||
"bluetooth smart" | ||
], | ||
@@ -25,2 +26,3 @@ "main": "./index.js", | ||
"dependencies": { | ||
"debug": "0.7.2" | ||
}, | ||
@@ -31,4 +33,4 @@ "devDependencies": { | ||
"scripts": { | ||
"pretest": "jshint *.js" | ||
"pretest": "jshint lib/*.js" | ||
} | ||
} |
199
README.md
@@ -45,2 +45,55 @@ noble | ||
Peripheral update RSSI | ||
peripheral.updateRssi(); | ||
Peripheral discover services | ||
peripheral.discoverServices(); // any service UUID | ||
var serviceUUIDs = ["<service UUID 1>", ...]; | ||
peripheral.discoverServices(serviceUUIDs); // particular UUID's | ||
Service discover included services | ||
service.discoverIncludedServices(); // any service UUID | ||
var serviceUUIDs = ["<service UUID 1>", ...]; | ||
service.discoverIncludedServices(serviceUUIDs); // particular UUID's | ||
Service discover characteristics | ||
service.discoverCharacteristics() // any characteristic UUID | ||
var characteristicUUIDs = ["<characteristic UUID 1>", ...]; | ||
service.discoverCharacteristics(characteristicUUIDs); // particular UUID's | ||
Characteristic read | ||
characteristic.read(); | ||
Characteristic write | ||
characteristic.write(data, notify); // data is a buffer, notify is true|false | ||
Characteristic broadcast | ||
characteristic.broadcast(broadcast); // broadcast is true|false | ||
Characteristic notify | ||
characteristic.notify(notify); // notify is true|false | ||
Characteristic discover descriptors | ||
characteristic.discoverDescriptors(); | ||
Descriptor read value | ||
descriptor.readValue(); | ||
Descriptor write value | ||
descriptor.writeValue(data); // data is a buffer | ||
__Events__ | ||
@@ -66,4 +119,8 @@ | ||
uuid: "<uuid>", | ||
localName: "<name>", | ||
services: ["<service UUID>", ...], | ||
advertisement: { | ||
localName: "<name>", | ||
serviceData: <Buffer>, | ||
txPowerLevel: <int>, | ||
serviceUuids: ["<service UUID>", ...], | ||
}, | ||
rssi: <rssi> | ||
@@ -80,15 +137,120 @@ }; | ||
Peripheral connect failure: | ||
Peripheral disconnected: | ||
noble.on('peripheralConnectFailure', callback(peripheral, reason)); | ||
noble.on('peripheralDisconnect', callback(peripheral)); | ||
peripheral.on('connectFailure', callback(reason)); | ||
peripheral.on('disconnect', callback); | ||
Peripheral RSSI update | ||
Peripheral disconnected: | ||
noble.on('peripheralRssiUpdate', callback(peripheral, rssi)); | ||
noble.on('peripheralDisonnect', callback(peripheral)); | ||
peripheral.on('rssiUpdate', callback(rssi)); | ||
peripheral.on('disconnect', callback); | ||
Peripheral services discovered | ||
noble.on('peripheralServicesDiscover', callback(peripheral, services)); | ||
peripheral.on('servicesDiscovered', callback(services)); | ||
Service included services discovered | ||
noble.on('peripheralServiceIncludedServicesDiscover', callback(peripheral, service, includedServiceUuids)); | ||
peripheral.on('serviceIncludedServicesDiscover', callback(service, includedServiceUuids)); | ||
service.on('includedServicesDiscover', callback(includedServiceUuids)); | ||
Service characteristics discovered | ||
characteristic = { | ||
uuid: "<uuid>", | ||
// properties: 'broadcast', 'read', 'writeWithoutResponse', 'write', 'notify', 'indicate', 'authenticatedSignedWrites', 'extendedProperties' | ||
properties: [...] | ||
}; | ||
noble.on('peripheralServiceCharacteristicsDiscover', callback(peripheral, service, characteristics)); | ||
peripheral.on('serviceCharacteristicsDiscover', callback(service, characteristics)); | ||
service.on('characteristicsDiscover', callback(characteristics)); | ||
Characteristic read | ||
noble.on('peripheralServiceCharacteristicRead', callback(peripheral, service, characteristic, data, isNotification)); | ||
peripheral.on('serviceCharacteristicRead', callback(service, characteristic, data, isNotification)); | ||
service.on('characteristicRead', callback(characteristic, data, isNotification)); | ||
characteristic.on('read', callback(data, isNotification)); | ||
Characteristic write | ||
noble.on('peripheralServiceCharacteristicWrite', callback(peripheral, service, characteristic)); | ||
peripheral.on('serviceCharacteristicWrite', callback(service, characteristic)); | ||
service.on('characteristicWrite', callback(characteristic)); | ||
characteristic.on('write', callback()); | ||
Characteristic broadcast | ||
noble.on('peripheralServiceCharacteristicBroadcast', callback(peripheral, service, characteristic, state)); | ||
peripheral.on('serviceCharacteristicBroadcast', callback(service, characteristic, state)); | ||
service.on('characteristicBroadcast', callback(characteristic, state)); | ||
characteristic.on('broadcast', callback(state)); | ||
Characteristic notify | ||
noble.on('peripheralServiceCharacteristicNotify', callback(peripheral, service, characteristic, state)); | ||
peripheral.on('serviceCharacteristicNotify', callback(service, characteristic, state)); | ||
service.on('characteristicNotify', callback(characteristic, state)); | ||
characteristic.on('notify', callback(state)); | ||
Characteristic descriptors discovered | ||
descriptor = { | ||
uuid: '<uuid>' | ||
}; | ||
noble.on('peripheralServiceCharacteristicDescriptorsDiscover', callback(peripheral, service, characteristic, descriptors)); | ||
peripheral.on('serviceCharacteristicDescriptorsDiscover', callback(service, characteristic, descriptors)); | ||
service.on('characteristicDescriptorsDiscover', callback(characteristic, descriptors)); | ||
characteristic.on('descriptorsDiscover', callback(descriptors)); | ||
Descriptor value read | ||
noble.on('peripheralServiceCharacteristicDescriptorValueRead', callback(peripheral, service, characteristic, descriptor, data)); | ||
peripheral.on('serviceCharacteristicDescriptorsValueRead', callback(service, characteristic, descriptor, data)); | ||
service.on('characteristicDescriptorValueRead', callback(characteristic, descriptor, data)); | ||
characteristic.on('descriptorValueRead', callback(descriptor, data)); | ||
descriptor.on('valueRead', data); | ||
Descriptor value write | ||
noble.on('peripheralServiceCharacteristicDescriptorValueWrite', callback(peripheral, service, characteristic, descriptor)); | ||
peripheral.on('serviceCharacteristicDescriptorsValueWrite', callback(service, characteristic, descriptor)); | ||
service.on('characteristicDescriptorValueWrite', callback(characteristic, descriptor)); | ||
characteristic.on('descriptorValueWrite', callback(descriptor)); | ||
descriptor.on('valueWrite'); | ||
Roadmap (TODO) | ||
@@ -104,9 +266,22 @@ -------------- | ||
* ~~stopScanning~~ | ||
* Peripheral (uuid, local name, service UUID's, RSSI) | ||
* ~~Peripheral~~ | ||
* ~~discovered~~ | ||
* ~~connect~~ | ||
* ~~disconnect/cancel connect~~ | ||
* discover services | ||
* read | ||
* write | ||
* ~~update RSSI~~ | ||
* ~~services~~ | ||
* ~~discover~~ | ||
* ~~disover included~~ | ||
* ~~discover characteristics for services~~ | ||
* ~~characteristics~~ | ||
* ~~read~~ | ||
* ~~write~~ | ||
* ~~set broadcast value~~ | ||
* ~~set notify value~~ | ||
* ~~descriptors~~ | ||
* ~~discover~~ | ||
* ~~read~~ | ||
* ~~write~~ | ||
* error handling | ||
* Linux | ||
@@ -113,0 +288,0 @@ * TDB |
235
test.js
@@ -5,6 +5,11 @@ var noble = require('./index'); | ||
setInterval(function() { | ||
console.log(10000); | ||
}, 1000); | ||
noble.on('stateChange', function(state) { | ||
console.log('on -> stateChange: ' + state); | ||
if (state === 'poweredOn') { | ||
noble.startScanning(); | ||
} else { | ||
noble.stopScanning(); | ||
} | ||
}); | ||
@@ -19,9 +24,6 @@ noble.on('scanStart', function() { | ||
noble.on('stateChange', function(state) { | ||
console.log('on -> stateChange: ' + state); | ||
}); | ||
noble.on('peripheralDiscover', function(peripheral) { | ||
console.log('on -> peripheralDiscover: '); | ||
console.log(peripheral); | ||
console.log('on -> peripheralDiscover: ' + peripheral); | ||
@@ -32,14 +34,158 @@ noble.stopScanning(); | ||
console.log('on -> peripheral connect'); | ||
this.disconnect(); | ||
this.updateRssi(); | ||
}); | ||
peripheral.on('connectFailure', function(reason) { | ||
console.log('on -> peripheral connect failure'); | ||
console.log(reason); | ||
}); | ||
// peripheral.on('connectFailure', function(reason) { | ||
// console.log('on -> peripheral connect failure'); | ||
// console.log(reason); | ||
// }); | ||
peripheral.on('disconnect', function() { | ||
console.log('on -> peripheral diconnect'); | ||
console.log('on -> peripheral disconnect'); | ||
}); | ||
peripheral.on('rssiUpdate', function(rssi) { | ||
console.log('on -> peripheral RSSI update ' + rssi); | ||
this.discoverServices(); | ||
}); | ||
peripheral.on('servicesDiscover', function(services) { | ||
console.log('on -> peripheral services discovered ' + services); | ||
var serviceIndex = 1; | ||
services[serviceIndex].on('includedServicesDiscover', function(includedServiceUuids) { | ||
console.log('on -> service included services discovered ' + includedServiceUuids); | ||
this.discoverCharacteristics(); | ||
}); | ||
services[serviceIndex].on('characteristicsDiscover', function(characteristics) { | ||
console.log('on -> service characteristics discovered ' + characteristics); | ||
var characteristicIndex = 0; | ||
characteristics[characteristicIndex].on('read', function(data, isNotification) { | ||
console.log('on -> characteristic read ' + data + ' ' + isNotification); | ||
console.log(data); | ||
}); | ||
characteristics[characteristicIndex].on('write', function() { | ||
console.log('on -> characteristic write '); | ||
}); | ||
characteristics[characteristicIndex].on('broadcast', function(state) { | ||
console.log('on -> characteristic broadcast ' + state); | ||
}); | ||
characteristics[characteristicIndex].on('notify', function(state) { | ||
console.log('on -> characteristic notify ' + state); | ||
}); | ||
characteristics[characteristicIndex].on('descriptorsDiscover', function(descriptors) { | ||
console.log('on -> characteristic descriptors discover ' + descriptors); | ||
var descriptorIndex = 0; | ||
descriptors[descriptorIndex].on('valueRead', function(data) { | ||
console.log('on -> descriptor value read ' + data); | ||
console.log(data); | ||
}); | ||
descriptors[descriptorIndex].on('valueWrite', function() { | ||
console.log('on -> descriptor value write '); | ||
}); | ||
descriptors[descriptorIndex].readValue(); | ||
descriptors[descriptorIndex].writeValue(new Buffer(0)); | ||
}); | ||
characteristics[characteristicIndex].on('descriptorValueRead', function(descriptor, data) { | ||
console.log('on -> characteristic descriptor value read ' + descriptor + ' ' + data); | ||
}); | ||
characteristics[characteristicIndex].on('descriptorValueWrite', function(descriptor) { | ||
console.log('on -> characteristic descriptor value write ' + descriptor); | ||
}); | ||
//characteristics[characteristicIndex].read(); | ||
//characteristics[characteristicIndex].write(new Buffer('hello')); | ||
//characteristics[characteristicIndex].broadcast(true); | ||
//characteristics[characteristicIndex].notify(true); | ||
characteristics[characteristicIndex].discoverDescriptors(); | ||
}); | ||
services[serviceIndex].on('characteristicRead', function(characteristic, data, isNotification) { | ||
console.log('on -> service characteristic read ' + characteristic + ' ' + data + ' ' + isNotification); | ||
peripheral.disconnect(); | ||
}); | ||
services[serviceIndex].on('characteristicWrite', function(characteristic) { | ||
console.log('on -> service characteristic write ' + characteristic); | ||
peripheral.disconnect(); | ||
}); | ||
services[serviceIndex].on('characteristicBroadcast', function(characteristic, state) { | ||
console.log('on -> service characteristic broadcast ' + characteristic + ' ' + state); | ||
peripheral.disconnect(); | ||
}); | ||
services[serviceIndex].on('characteristicNotify', function(characteristic, state) { | ||
console.log('on -> service characteristic notify ' + characteristic + ' ' + state); | ||
// peripheral.disconnect(); | ||
}); | ||
services[serviceIndex].on('characteristicDescriptorsDiscover', function(characteristic, descriptors) { | ||
console.log('on -> service characteristic descriptors discover ' + characteristic + ' ' + descriptors); | ||
// peripheral.disconnect(); | ||
}); | ||
services[serviceIndex].on('characteristicDescriptorValueRead', function(characteristic, descriptor, data) { | ||
console.log('on -> service characteristic descriptor value read ' + characteristic + ' ' + descriptor + ' ' + data); | ||
peripheral.disconnect(); | ||
}); | ||
services[serviceIndex].on('characteristicDescriptorValueWrite', function(characteristic, descriptor) { | ||
console.log('on -> service characteristic descriptor value write ' + characteristic + ' ' + descriptor); | ||
peripheral.disconnect(); | ||
}); | ||
services[serviceIndex].discoverIncludedServices(); | ||
}); | ||
peripheral.on('serviceIncludedServicesDiscover', function(service, includedServiceUuids) { | ||
console.log('on -> peripheral service included services discovered ' + service + ' ' + includedServiceUuids); | ||
}); | ||
peripheral.on('serviceCharacteristicsDiscover', function(service, characteristics) { | ||
console.log('on -> peripheral service characteristics discovered ' + service + ' ' + characteristics); | ||
}); | ||
peripheral.on('serviceCharacteristicRead', function(service, characteristic, data, isNotification) { | ||
console.log('on -> peripheral service characteristic read ' + service + ' ' + characteristic + ' ' + data + ' ' + isNotification); | ||
}); | ||
peripheral.on('serviceCharacteristicWrite', function(service, characteristic) { | ||
console.log('on -> peripheral service characteristic write ' + service + ' ' + characteristic); | ||
}); | ||
peripheral.on('serviceCharacteristicBroadcast', function(service, characteristic, state) { | ||
console.log('on -> peripheral service characteristic broadcast ' + service + ' ' + characteristic + ' ' + state); | ||
}); | ||
peripheral.on('serviceCharacteristicNotify', function(service, characteristic, state) { | ||
console.log('on -> peripheral service characteristic notify ' + service + ' ' + characteristic + ' ' + state); | ||
}); | ||
peripheral.on('serviceCharacteristicDescriptorsDiscover', function(service, characteristic, descriptors) { | ||
console.log('on -> peripheral service characteristic descriptors discover ' + service + ' ' + characteristic + ' ' + descriptors); | ||
}); | ||
peripheral.on('serviceCharacteristicDescriptorValueRead', function(service, characteristic, descriptor, data) { | ||
console.log('on -> peripheral service characteristic descriptor value read ' + service + ' ' + characteristic + ' ' + descriptor + ' ' + data); | ||
}); | ||
peripheral.on('serviceCharacteristicDescriptorValueWrite', function(service, characteristic, descriptor) { | ||
console.log('on -> peripheral service characteristic descriptor value write ' + service + ' ' + characteristic + ' ' + descriptor); | ||
}); | ||
peripheral.connect(); | ||
@@ -49,18 +195,57 @@ }); | ||
noble.on('peripheralConnect', function(peripheral) { | ||
console.log('on -> peripheralConnect: '); | ||
console.log(peripheral); | ||
console.log('on -> peripheralConnect: ' + peripheral); | ||
}); | ||
noble.on('peripheralConnectFailure', function(peripheral, reason) { | ||
console.log('on -> peripheralConnectFailure: '); | ||
console.log(peripheral); | ||
console.log(reason); | ||
}); | ||
// noble.on('peripheralConnectFailure', function(peripheral, reason) { | ||
// console.log('on -> peripheralConnectFailure: '); | ||
// console.log(peripheral); | ||
// console.log(reason); | ||
// }); | ||
noble.on('peripheralDisconnect', function(peripheral) { | ||
console.log('on -> peripheralDisonnect: '); | ||
console.log(peripheral); | ||
console.log('on -> peripheralDisconnect: ' + peripheral); | ||
}); | ||
noble.startScanning(); | ||
noble.on('peripheralRssiUpdate', function(peripheral, rssi) { | ||
console.log('on -> peripheralRssiUpdate: ' + peripheral + ' ' + rssi); | ||
}); | ||
noble.on('peripheralServicesDiscover', function(peripheral, services) { | ||
console.log('on -> peripheralServicesDiscover: ' + peripheral + ' ' + services); | ||
}); | ||
noble.on('peripheralServiceIncludedServicesDiscover', function(peripheral, service, includedServiceUuids) { | ||
console.log('on -> peripheralServicesDiscover: ' + peripheral + ' ' + service + ' ' + includedServiceUuids); | ||
}); | ||
noble.on('peripheralServiceCharacteristicsDiscover', function(peripheral, service, characteristics) { | ||
console.log('on -> peripheralServiceCharacteristicsDiscover: ' + peripheral + ' ' + service + ' ' + characteristics); | ||
}); | ||
noble.on('peripheralServiceCharacteristicRead', function(peripheral, service, characteristic, data, isNotification) { | ||
console.log('on -> peripheralServiceCharacteristicRead: ' + peripheral + ' ' + service + ' ' + characteristic + ' ' + data + ' ' + isNotification); | ||
}); | ||
noble.on('peripheralServiceCharacteristicWrite', function(peripheral, service, characteristic) { | ||
console.log('on -> peripheralServiceCharacteristicWrite: ' + peripheral + ' ' + service + ' ' + characteristic); | ||
}); | ||
noble.on('peripheralServiceCharacteristicBroadcast', function(peripheral, service, characteristic, state) { | ||
console.log('on -> peripheralServiceCharacteristicBroadcast: ' + peripheral + ' ' + service + ' ' + characteristic + ' ' + state); | ||
}); | ||
noble.on('peripheralServiceCharacteristicNotify', function(peripheral, service, characteristic, state) { | ||
console.log('on -> peripheralServiceCharacteristicNotify: ' + peripheral + ' ' + service + ' ' + characteristic + ' ' + state); | ||
}); | ||
noble.on('peripheralServiceCharacteristicDescriptorsDiscover', function(peripheral, service, characteristic, descriptors) { | ||
console.log('on -> peripheralServiceCharacteristicDescriptorsDiscover: ' + peripheral + ' ' + service + ' ' + characteristic + ' ' + descriptors); | ||
}); | ||
noble.on('peripheralServiceCharacteristicDescriptorValueRead', function(peripheral, service, characteristic, descriptor, data) { | ||
console.log('on -> peripheralServiceCharacteristicDescriptorValueRead: ' + peripheral + ' ' + service + ' ' + characteristic + ' ' + descriptor + ' ' + data); | ||
}); | ||
noble.on('peripheralServiceCharacteristicDescriptorValueWrite', function(peripheral, service, characteristic, descriptor) { | ||
console.log('on -> peripheralServiceCharacteristicDescriptorValueWrite: ' + peripheral + ' ' + service + ' ' + characteristic + ' ' + descriptor); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
71847
1087
297
1
14
2
+ Addeddebug@0.7.2
+ Addeddebug@0.7.2(transitive)