Comparing version 1.3.0 to 1.4.0
@@ -0,1 +1,8 @@ | ||
## Version 1.4.0 | ||
* hci-socket binding: include service data UUID's when filtering discover | ||
* hci-socket binding: emit scan start/stop when external app changes scanning start ([@bradjc](https://github.com/bradjc)) | ||
* Support for pluggable bindings ([@hgwood](https://github.com/hgwood)) | ||
* hci-socket binding: don't kill all descriptors when looking for new Characteristics ([@Neutrosider](https://github.com/Neutrosider)) | ||
## Version 1.3.0 | ||
@@ -2,0 +9,0 @@ |
var async = require('async'); | ||
var noble = require('../index'); | ||
var peripheralId = process.argv[2]; | ||
var peripheralIdOrAddress = process.argv[2].toLowerCase(); | ||
@@ -15,6 +15,6 @@ noble.on('stateChange', function(state) { | ||
noble.on('discover', function(peripheral) { | ||
if (peripheral.id === peripheralId) { | ||
if (peripheral.id === peripheralIdOrAddress || peripheral.address === peripheralIdOrAddress) { | ||
noble.stopScanning(); | ||
console.log('peripheral with ID ' + peripheralId + ' found'); | ||
console.log('peripheral with ID ' + peripheral.id + ' found'); | ||
var advertisement = peripheral.advertisement; | ||
@@ -21,0 +21,0 @@ |
var Noble = require('./lib/noble'); | ||
var bindings = require('./lib/resolve-bindings')(); | ||
module.exports = new Noble(); | ||
module.exports = new Noble(bindings); |
@@ -128,4 +128,4 @@ var debug = require('debug')('bindings'); | ||
NobleBindings.prototype.onScanStart = function() { | ||
this.emit('scanStart'); | ||
NobleBindings.prototype.onScanStart = function(filterDuplicates) { | ||
this.emit('scanStart', filterDuplicates); | ||
}; | ||
@@ -142,7 +142,16 @@ | ||
var serviceUuids = advertisement.serviceUuids; | ||
var serviceUuids = advertisement.serviceUuids || []; | ||
var serviceData = advertisement.serviceData || []; | ||
var hasScanServiceUuids = (this._scanServiceUuids.length === 0); | ||
if (!hasScanServiceUuids) { | ||
for (var i in serviceUuids) { | ||
var i; | ||
serviceUuids = serviceUuids.slice(); | ||
for (i in serviceData) { | ||
serviceUuids.push(serviceData[i].uuid); | ||
} | ||
for (i in serviceUuids) { | ||
hasScanServiceUuids = (this._scanServiceUuids.indexOf(serviceUuids[i]) !== -1); | ||
@@ -149,0 +158,0 @@ |
@@ -10,2 +10,3 @@ var debug = require('debug')('gap'); | ||
this._scanState = null; | ||
this._scanFilterDuplicates = null; | ||
this._discoveries = {}; | ||
@@ -17,2 +18,4 @@ | ||
this._hci.on('leAdvertisingReport', this.onHciLeAdvertisingReport.bind(this)); | ||
this._hci.on('leScanEnableSetCmd', this.onLeScanEnableSetCmd.bind(this)); | ||
}; | ||
@@ -24,4 +27,5 @@ | ||
this._scanState = 'starting'; | ||
this._scanFilterDuplicates = !allowDuplicates; | ||
this._hci.setScanEnabled(true, !allowDuplicates); | ||
this._hci.setScanEnabled(true, this._scanFilterDuplicates); | ||
}; | ||
@@ -43,7 +47,15 @@ | ||
Gap.prototype.onHciLeScanEnableSet = function() { | ||
// Called when receive an event "Command Complete" for "LE Set Scan Enable" | ||
Gap.prototype.onHciLeScanEnableSet = function(status) { | ||
// Check the status we got from the command complete function. | ||
if (status !== 0) { | ||
// If it is non-zero there was an error, and we should not change | ||
// our status as a result. | ||
return; | ||
} | ||
if (this._scanState === 'starting') { | ||
this._scanState = 'stared'; | ||
this._scanState = 'started'; | ||
this.emit('scanStart'); | ||
this.emit('scanStart', this._scanFilterDuplicates); | ||
} else if (this._scanState === 'stopping') { | ||
@@ -56,2 +68,23 @@ this._scanState = 'stopped'; | ||
// Called when we see the actual command "LE Set Scan Enable" | ||
Gap.prototype.onLeScanEnableSetCmd = function(enable, filterDuplicates) { | ||
// Check to see if the new settings differ from what we expect. | ||
// If we are scanning, then a change happens if the new command stops | ||
// scanning or if duplicate filtering changes. | ||
// If we are not scanning, then a change happens if scanning was enabled. | ||
if ((this._scanState == 'starting' || this._scanState == 'started')) { | ||
if (!enable) { | ||
this.emit('scanStop'); | ||
} else if (this._scanFilterDuplicates !== filterDuplicates) { | ||
this._scanFilterDuplicates = filterDuplicates; | ||
this.emit('scanStart', this._scanFilterDuplicates); | ||
} | ||
} else if ((this._scanState == 'stopping' || this._scanState == 'stopped') && | ||
(enable)) { | ||
// Someone started scanning on us. | ||
this.emit('scanStart', this._scanFilterDuplicates); | ||
} | ||
}; | ||
Gap.prototype.onHciLeAdvertisingReport = function(status, type, address, addressType, eir, rssi) { | ||
@@ -58,0 +91,0 @@ var previouslyDiscovered = !!this._discoveries[address]; |
@@ -170,6 +170,6 @@ var debug = require('debug')('att'); | ||
buf.writeUInt8(ATT_OP_ERROR, 0); | ||
buf.writeUInt8(ATT_OP_ERROR, 0); | ||
buf.writeUInt8(opcode, 1); | ||
buf.writeUInt16LE(handle, 2); | ||
buf.writeUInt8(status, 4); | ||
buf.writeUInt8(status, 4); | ||
@@ -384,3 +384,3 @@ return buf; | ||
this._characteristics[serviceUuid] = {}; | ||
this._descriptors[serviceUuid] = {}; | ||
this._descriptors[serviceUuid] = this._descriptors[serviceUuid] || {}; | ||
@@ -387,0 +387,0 @@ var callback = function(data) { |
@@ -119,3 +119,3 @@ var debug = require('debug')('hci'); | ||
var filter = new Buffer(14); | ||
var typeMask = (1 << HCI_EVENT_PKT)| (1 << HCI_ACLDATA_PKT); | ||
var typeMask = (1 << HCI_COMMAND_PKT) | (1 << HCI_EVENT_PKT) | (1 << HCI_ACLDATA_PKT); | ||
var eventMask1 = (1 << EVT_DISCONN_COMPLETE) | (1 << EVT_ENCRYPT_CHANGE) | (1 << EVT_CMD_COMPLETE) | (1 << EVT_CMD_STATUS); | ||
@@ -472,2 +472,19 @@ var eventMask2 = (1 << (EVT_LE_META_EVENT - 32)); | ||
} | ||
} else if (HCI_COMMAND_PKT === eventType) { | ||
cmd = data.readUInt16LE(1); | ||
var len = data.readUInt8(3); | ||
debug('\t\tcmd = ' + cmd); | ||
debug('\t\tdata len = ' + len); | ||
if (cmd === LE_SET_SCAN_ENABLE_CMD) { | ||
var enable = (data.readUInt8(4) === 0x1); | ||
var filterDuplicates = (data.readUInt8(5) === 0x1); | ||
debug('\t\t\tLE enable scan command'); | ||
debug('\t\t\tenable scanning = ' + enable); | ||
debug('\t\t\tfilter duplicates = ' + filterDuplicates); | ||
this.emit('leScanEnableSetCmd', enable, filterDuplicates); | ||
} | ||
} | ||
@@ -520,3 +537,3 @@ }; | ||
} else if (cmd === LE_SET_SCAN_ENABLE_CMD) { | ||
this.emit('leScanEnableSet'); | ||
this.emit('leScanEnableSet', status); | ||
} else if (cmd === READ_RSSI_CMD) { | ||
@@ -523,0 +540,0 @@ var handle = result.readUInt16LE(0); |
var debug = require('debug')('noble'); | ||
var events = require('events'); | ||
var os = require('os'); | ||
var util = require('util'); | ||
@@ -12,19 +11,3 @@ | ||
var bindings = null; | ||
var platform = os.platform(); | ||
if (process.env.NOBLE_WEBSOCKET || process.title === 'browser') { | ||
bindings = require('./websocket/bindings'); | ||
} else if (process.env.NOBLE_DISTRIBUTED) { | ||
bindings = require('./distributed/bindings'); | ||
} else if (platform === 'darwin') { | ||
bindings = require('./mac/bindings'); | ||
} else if (platform === 'linux' || platform === 'win32') { | ||
bindings = require('./hci-socket/bindings'); | ||
} else { | ||
throw new Error('Unsupported platform'); | ||
} | ||
function Noble() { | ||
function Noble(bindings) { | ||
this.state = 'unknown'; | ||
@@ -108,5 +91,5 @@ this.address = 'unknown'; | ||
Noble.prototype.onScanStart = function() { | ||
Noble.prototype.onScanStart = function(filterDuplicates) { | ||
debug('scanStart'); | ||
this.emit('scanStart'); | ||
this.emit('scanStart', filterDuplicates); | ||
}; | ||
@@ -113,0 +96,0 @@ |
@@ -6,3 +6,3 @@ { | ||
"description": "A Node.js BLE (Bluetooth Low Energy) central library.", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
# noble | ||
[![Build Status](https://travis-ci.org/sandeepmistry/noble.svg?branch=master)](https://travis-ci.org/sandeepmistry/noble) | ||
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/sandeepmistry/noble?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
@@ -55,4 +56,6 @@ | ||
### Maximum simulanteous connections | ||
### Maximum simultaneous connections | ||
This limit is imposed upon by the Bluetooth adapter hardware as well as it's firmware. | ||
| Platform | | | ||
@@ -174,5 +177,9 @@ | :------- | --- | | ||
```javascript | ||
characteristic.write(data, notify[, callback(error)]); // data is a buffer, notify is true|false | ||
characteristic.write(data, withoutResponse[, callback(error)]); // data is a buffer, withoutResponse is true|false | ||
``` | ||
* ```withoutResponse```: | ||
* ```false```: send a write request, used with "write" characteristic property | ||
* ```true```: send a write command, used with "write without response" characteristic property | ||
##### Broadcast | ||
@@ -227,2 +234,4 @@ | ||
See [Node.js EventEmitter docs](https://nodejs.org/api/events.html) for more info. on API's. | ||
#### Adapter state change | ||
@@ -242,2 +251,4 @@ | ||
The event is emitted when scanning is started or if another application enables scanning or changes scanning settings. | ||
#### Scan stopped | ||
@@ -249,2 +260,4 @@ | ||
The event is emitted when scanning is stopped or if another application stops scanning. | ||
#### Peripheral discovered | ||
@@ -288,3 +301,3 @@ | ||
```javascript | ||
peripheral.on('connect', callback); | ||
peripheral.once('connect', callback); | ||
``` | ||
@@ -295,3 +308,3 @@ | ||
```javascript | ||
peripheral.on('disconnect', callback); | ||
peripheral.once('disconnect', callback); | ||
``` | ||
@@ -302,3 +315,3 @@ | ||
```javascript | ||
peripheral.on('rssiUpdate', callback(rssi)); | ||
peripheral.once('rssiUpdate', callback(rssi)); | ||
``` | ||
@@ -309,3 +322,3 @@ | ||
```javascript | ||
peripheral.on('servicesDiscover', callback(services)); | ||
peripheral.once('servicesDiscover', callback(services)); | ||
``` | ||
@@ -318,3 +331,3 @@ | ||
```javascript | ||
service.on('includedServicesDiscover', callback(includedServiceUuids)); | ||
service.once('includedServicesDiscover', callback(includedServiceUuids)); | ||
``` | ||
@@ -331,3 +344,3 @@ | ||
service.on('characteristicsDiscover', callback(characteristics)); | ||
service.once('characteristicsDiscover', callback(characteristics)); | ||
``` | ||
@@ -344,3 +357,3 @@ | ||
characteristic.on('read', callback(data, isNotification)); // legacy | ||
characteristic.once('read', callback(data, isNotification)); // legacy | ||
``` | ||
@@ -353,3 +366,3 @@ | ||
```javascript | ||
characteristic.on('write', withoutResponse, callback()); | ||
characteristic.once('write', withoutResponse, callback()); | ||
``` | ||
@@ -362,3 +375,3 @@ | ||
```javascript | ||
characteristic.on('broadcast', callback(state)); | ||
characteristic.once('broadcast', callback(state)); | ||
``` | ||
@@ -371,3 +384,3 @@ | ||
```javascript | ||
characteristic.on('notify', callback(state)); | ||
characteristic.once('notify', callback(state)); | ||
``` | ||
@@ -382,3 +395,3 @@ | ||
characteristic.on('descriptorsDiscover', callback(descriptors)); | ||
characteristic.once('descriptorsDiscover', callback(descriptors)); | ||
``` | ||
@@ -391,3 +404,3 @@ | ||
```javascript | ||
descriptor.on('valueRead', data); | ||
descriptor.once('valueRead', data); | ||
``` | ||
@@ -398,3 +411,3 @@ | ||
```javascript | ||
descriptor.on('valueWrite'); | ||
descriptor.once('valueWrite'); | ||
``` | ||
@@ -438,2 +451,12 @@ | ||
## Advanced usage | ||
### Override default bindings | ||
By default, noble will select bindings to communicate with Bluetooth devices depending on your platform. If you prefer to specify what bindings noble should use: | ||
```javascript | ||
var noble = require('noble/with-bindings')(require('./my-custom-bindings')); | ||
``` | ||
## Useful Links | ||
@@ -440,0 +463,0 @@ |
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
284052
46
6689
461