Comparing version 0.3.7 to 0.3.8
@@ -28,4 +28,10 @@ var os = require('os'); | ||
nodeGypConfigureBuild.on('close', function(code) { | ||
console.log('noble install: done'); | ||
console.log('noble install: ' + ((code === 0) ? 'done' : 'error')); | ||
if (code !== 0) { | ||
console.error('Have you installed "libbluetooth-dev"?'); | ||
console.error(); | ||
console.error('Please see README https://github.com/sandeepmistry/noble#prerequisites'); | ||
} | ||
process.exit(code); | ||
@@ -32,0 +38,0 @@ }); |
@@ -52,2 +52,4 @@ var debug = require('debug')('hci-ble'); | ||
console.log('noble warning: adapter state unauthorized, please run as root or with sudo'); | ||
console.log(' or see README for information on running without root/sudo:'); | ||
console.log(' https://github.com/sandeepmistry/noble#running-on-linux'); | ||
} | ||
@@ -54,0 +56,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "A node.js BLE (Bluetooth low energy) central library.", | ||
"version": "0.3.7", | ||
"version": "0.3.8", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
392
README.md
@@ -1,5 +0,4 @@ | ||
noble | ||
===== | ||
# noble | ||
[![Analytics](https://ga-beacon.appspot.com/UA-56089547-1/sandeepmistry/noble?pixel)](https://github.com/igrigorik/ga-beacon) | ||
[![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) | ||
@@ -10,230 +9,343 @@ A node.js BLE (Bluetooth low energy) central module. | ||
__Note:__ Mac OS X and Linux are currently the only supported OSes, and are still under development. Other platforms will be developed later on (see Roadmap below). | ||
__Note:__ Mac OS X and Linux are currently the only supported OSes. Other platforms may be developed later on (see Roadmap below). | ||
Prerequisites | ||
------------ | ||
## Prerequisites | ||
__OS X__ | ||
### OS X | ||
* install [Xcode](https://itunes.apple.com/ca/app/xcode/id497799835?mt=12) | ||
__Linux (Ubuntu)__ | ||
### Linux (Ubuntu) | ||
* Kernel version 3.6 or above | ||
* ```sudo apt-get install bluetooth bluez-utils libbluetooth-dev``` | ||
* Run as ```sudo``` or ```root``` | ||
* ```libbluetooth-dev``` | ||
Install | ||
------- | ||
#### Ubuntu/Debian/Raspbian | ||
npm install noble | ||
```sh | ||
sudo apt-get install bluetooth bluez-utils libbluetooth-dev | ||
``` | ||
Usage | ||
----- | ||
#### Intel Edison | ||
var noble = require('noble'); | ||
See [Configure Intel Edison for Bluetooth LE (Smart) Development](http://rexstjohn.com/configure-intel-edison-for-bluetooth-le-smart-development/) | ||
__Actions__ | ||
## Install | ||
Start scanning: | ||
```sh | ||
npm install noble | ||
``` | ||
noble.startScanning(); // any service UUID, no duplicates | ||
## Usage | ||
```javascript | ||
var noble = require('noble'); | ||
``` | ||
noble.startScanning([], true); // any service UUID, allow duplicates | ||
### Actions | ||
#### Start scanning | ||
var serviceUUIDs = ["<service UUID 1>", ...]; // default: [] => all | ||
var allowDuplicates = <false|true>; // default: false | ||
```javascript | ||
noble.startScanning(); // any service UUID, no duplicates | ||
noble.startScanning(serviceUUIDs, allowDuplicates); // particular UUID's | ||
Stop scanning: | ||
noble.startScanning([], true); // any service UUID, allow duplicates | ||
noble.stopScanning(); | ||
Peripheral connect: | ||
var serviceUUIDs = ["<service UUID 1>", ...]; // default: [] => all | ||
var allowDuplicates = <false|true>; // default: false | ||
peripheral.connect([callback(error)]); | ||
noble.startScanning(serviceUUIDs, allowDuplicates); // particular UUID's | ||
``` | ||
Peripheral disconnect or cancel pending connection: | ||
#### Stop scanning | ||
peripheral.disconnect([callback(error)]); | ||
```javascript | ||
noble.stopScanning(); | ||
``` | ||
Peripheral update RSSI | ||
#### Peripheral | ||
peripheral.updateRssi([callback(error, rssi)]); | ||
##### Connect | ||
Peripheral discover services | ||
```javascript | ||
peripheral.connect([callback(error)]); | ||
``` | ||
peripheral.discoverServices(); // any service UUID | ||
##### Disconnect or cancel pending connection | ||
var serviceUUIDs = ["<service UUID 1>", ...]; | ||
peripheral.discoverServices(serviceUUIDs[, callback(error, services)]); // particular UUID's | ||
```javascript | ||
peripheral.disconnect([callback(error)]); | ||
``` | ||
Peripheral discover all services and characteristics | ||
##### Update RSSI | ||
peripheral.discoverAllServicesAndCharacteristics([callback(error, services, characteristics)); | ||
```javascript | ||
peripheral.updateRssi([callback(error, rssi)]); | ||
``` | ||
Peripheral discover some services and characteristics | ||
##### Discover services | ||
var serviceUUIDs = ["<service UUID 1>", ...]; | ||
var characteristicUUIDs = ["<characteristic UUID 1>", ...]; | ||
peripheral.discoverSomeServicesAndCharacteristics(serviceUUIDs, characteristicUUIDs, [callback(error, services, characteristics)); | ||
```javascript | ||
peripheral.discoverServices(); // any service UUID | ||
Service discover included services | ||
var serviceUUIDs = ["<service UUID 1>", ...]; | ||
peripheral.discoverServices(serviceUUIDs[, callback(error, services)]); // particular UUID's | ||
``` | ||
service.discoverIncludedServices(); // any service UUID | ||
##### Discover all services and characteristics | ||
var serviceUUIDs = ["<service UUID 1>", ...]; | ||
service.discoverIncludedServices(serviceUUIDs[, callback(error, includedServiceUuids)]); // particular UUID's | ||
```javascript | ||
peripheral.discoverAllServicesAndCharacteristics([callback(error, services, characteristics)); | ||
``` | ||
Service discover characteristics | ||
##### Discover some services and characteristics | ||
service.discoverCharacteristics() // any characteristic UUID | ||
```javascript | ||
var serviceUUIDs = ["<service UUID 1>", ...]; | ||
var characteristicUUIDs = ["<characteristic UUID 1>", ...]; | ||
peripheral.discoverSomeServicesAndCharacteristics(serviceUUIDs, characteristicUUIDs, [callback(error, services, characteristics)); | ||
``` | ||
#### Service | ||
var characteristicUUIDs = ["<characteristic UUID 1>", ...]; | ||
service.discoverCharacteristics(characteristicUUIDs[, callback(error, characteristics)]); // particular UUID's | ||
##### Discover included services | ||
Characteristic read | ||
```javascript | ||
service.discoverIncludedServices(); // any service UUID | ||
characteristic.read([callback(error, data)]); | ||
var serviceUUIDs = ["<service UUID 1>", ...]; | ||
service.discoverIncludedServices(serviceUUIDs[, callback(error, includedServiceUuids)]); // particular UUID's | ||
``` | ||
Characteristic write | ||
##### Discover characteristics | ||
characteristic.write(data, notify[, callback(error)]); // data is a buffer, notify is true|false | ||
```javascript | ||
service.discoverCharacteristics() // any characteristic UUID | ||
Characteristic broadcast | ||
var characteristicUUIDs = ["<characteristic UUID 1>", ...]; | ||
service.discoverCharacteristics(characteristicUUIDs[, callback(error, characteristics)]); // particular UUID's | ||
``` | ||
characteristic.broadcast(broadcast[, callback(error)]); // broadcast is true|false | ||
#### Characteristic | ||
Characteristic notify | ||
##### Read | ||
characteristic.notify(notify[, callback(error)]); // notify is true|false | ||
```javascript | ||
characteristic.read([callback(error, data)]); | ||
``` | ||
##### Write | ||
```javascript | ||
characteristic.write(data, notify[, callback(error)]); // data is a buffer, notify is true|false | ||
``` | ||
##### Broadcast | ||
```javascript | ||
characteristic.broadcast(broadcast[, callback(error)]); // broadcast is true|false | ||
``` | ||
##### Notify | ||
```javascript | ||
characteristic.notify(notify[, callback(error)]); // notify is true|false | ||
``` | ||
* use for characteristics with notifiy or indicate properties | ||
Characteristic discover descriptors | ||
##### Discover descriptors | ||
characteristic.discoverDescriptors([callback(error, descriptors)]); | ||
```javascript | ||
characteristic.discoverDescriptors([callback(error, descriptors)]); | ||
``` | ||
Descriptor read value | ||
##### Read value | ||
descriptor.readValue([callback(error, data)]); | ||
```javascript | ||
descriptor.readValue([callback(error, data)]); | ||
``` | ||
Descriptor write value | ||
##### Write value | ||
descriptor.writeValue(data[, callback(error)]); // data is a buffer | ||
```javascript | ||
descriptor.writeValue(data[, callback(error)]); // data is a buffer | ||
``` | ||
__Events__ | ||
#### Handle | ||
Adapter state change: | ||
##### Read | ||
state = <"unknown" | "resetting" | "unsupported" | "unauthorized" | "poweredOff" | "poweredOn"> | ||
```javascript | ||
peripheral.readHandle(handle, callback(error, data)); | ||
``` | ||
noble.on('stateChange', callback(state)); | ||
##### Write | ||
Scan started: | ||
```javascript | ||
peripheral.writeHandle(handle, data, withoutResponse, callback(error)); | ||
``` | ||
noble.on('scanStart', callback); | ||
### Events | ||
Scan stopped: | ||
#### Adapter state change | ||
noble.on('scanStop', callback); | ||
```javascript | ||
state = <"unknown" | "resetting" | "unsupported" | "unauthorized" | "poweredOff" | "poweredOn"> | ||
Peripheral discovered: | ||
noble.on('stateChange', callback(state)); | ||
``` | ||
peripheral = { | ||
uuid: "<uuid>", | ||
advertisement: { | ||
localName: "<name>", | ||
txPowerLevel: <int>, | ||
serviceUuids: ["<service UUID>", ...], | ||
manufacturerData: <Buffer>, | ||
serviceData: [ | ||
{ | ||
uuid: "<service UUID>" | ||
data: <Buffer> | ||
}, | ||
... | ||
] | ||
}, | ||
rssi: <rssi> | ||
}; | ||
#### Scan started: | ||
noble.on('discover', callback(peripheral)); | ||
```javascript | ||
noble.on('scanStart', callback); | ||
``` | ||
Peripheral connected: | ||
#### Scan stopped | ||
peripheral.on('connect', callback); | ||
```javascript | ||
noble.on('scanStop', callback); | ||
``` | ||
Peripheral disconnected: | ||
#### Peripheral discovered: | ||
peripheral.on('disconnect', callback); | ||
```javascript | ||
peripheral = { | ||
uuid: "<uuid>", | ||
advertisement: { | ||
localName: "<name>", | ||
txPowerLevel: <int>, | ||
serviceUuids: ["<service UUID>", ...], | ||
manufacturerData: <Buffer>, | ||
serviceData: [ | ||
{ | ||
uuid: "<service UUID>" | ||
data: <Buffer> | ||
}, | ||
... | ||
] | ||
}, | ||
rssi: <rssi> | ||
}; | ||
Peripheral RSSI update | ||
noble.on('discover', callback(peripheral)); | ||
``` | ||
peripheral.on('rssiUpdate', callback(rssi)); | ||
#### Peripheral | ||
Peripheral services discovered | ||
##### Connected | ||
peripheral.on('servicesDiscover', callback(services)); | ||
```javascript | ||
peripheral.on('connect', callback); | ||
``` | ||
Service included services discovered | ||
##### Disconnected: | ||
service.on('includedServicesDiscover', callback(includedServiceUuids)); | ||
```javascript | ||
peripheral.on('disconnect', callback); | ||
``` | ||
Service characteristics discovered | ||
##### RSSI update | ||
characteristic = { | ||
uuid: "<uuid>", | ||
// properties: 'broadcast', 'read', 'writeWithoutResponse', 'write', 'notify', 'indicate', 'authenticatedSignedWrites', 'extendedProperties' | ||
properties: [...] | ||
}; | ||
```javascript | ||
peripheral.on('rssiUpdate', callback(rssi)); | ||
``` | ||
service.on('characteristicsDiscover', callback(characteristics)); | ||
##### Services discovered | ||
Characteristic read | ||
```javascript | ||
peripheral.on('servicesDiscover', callback(services)); | ||
``` | ||
characteristic.on('read', callback(data, isNotification)); | ||
#### Service | ||
Characteristic write | ||
##### Included services discovered | ||
characteristic.on('write', withoutResponse, callback()); | ||
```javascript | ||
service.on('includedServicesDiscover', callback(includedServiceUuids)); | ||
``` | ||
Characteristic broadcast | ||
##### Characteristics discovered | ||
characteristic.on('broadcast', callback(state)); | ||
```javascript | ||
characteristic = { | ||
uuid: "<uuid>", | ||
// properties: 'broadcast', 'read', 'writeWithoutResponse', 'write', 'notify', 'indicate', 'authenticatedSignedWrites', 'extendedProperties' | ||
properties: [...] | ||
}; | ||
Characteristic notify | ||
service.on('characteristicsDiscover', callback(characteristics)); | ||
``` | ||
characteristic.on('notify', callback(state)); | ||
#### Characteristic | ||
Characteristic descriptors discovered | ||
##### Read | ||
descriptor = { | ||
uuid: '<uuid>' | ||
}; | ||
```javascript | ||
characteristic.on('read', callback(data, isNotification)); | ||
``` | ||
characteristic.on('descriptorsDiscover', callback(descriptors)); | ||
##### Write | ||
Descriptor value read | ||
```javascript | ||
characteristic.on('write', withoutResponse, callback()); | ||
``` | ||
descriptor.on('valueRead', data); | ||
##### Broadcast | ||
Descriptor value write | ||
```javascript | ||
characteristic.on('broadcast', callback(state)); | ||
``` | ||
descriptor.on('valueWrite'); | ||
##### Notify | ||
Read handle | ||
```javascript | ||
characteristic.on('notify', callback(state)); | ||
``` | ||
peripheral.readHandle(handle, callback(error, data)); | ||
##### Descriptors discovered | ||
Write handle | ||
```javascript | ||
descriptor = { | ||
uuid: '<uuid>' | ||
}; | ||
peripheral.writeHandle(handle, data, withoutResponse, callback(error)); | ||
characteristic.on('descriptorsDiscover', callback(descriptors)); | ||
``` | ||
Running on Linux | ||
----------------- | ||
Must be run with ```sudo``` or as root user. | ||
#### Descriptor | ||
##### Value read | ||
```javascript | ||
descriptor.on('valueRead', data); | ||
``` | ||
##### Value write | ||
```javascript | ||
descriptor.on('valueWrite'); | ||
``` | ||
## Running on Linux | ||
### Running without root/sudo | ||
Run the following command in the directory you ran ```npm install``` from: | ||
```sh | ||
find -path '*noble*Release/hci-ble' -exec sudo setcap cap_net_raw+eip '{}' \; | ||
``` | ||
This grants noble's ```hci-ble``` binary ```cap_net_raw``` privileges, so it can start/stop scanning for BLE devices. | ||
__Note:__ The above command requires ```setcap``` to be installed, it can be installed using the following: | ||
* apt: ```sudo apt-get install libcap2-bin``` | ||
* yum: ```su -c \'yum install libcap2-bin\'``` | ||
### Multiple Adapters | ||
```hci0``` is used by default to override set the ```NOBLE_HCI_DEVICE_ID``` environment variable to the interface number. | ||
@@ -243,6 +355,7 @@ | ||
sudo NOBLE_HCI_DEVICE_ID=1 node <your file>.js | ||
```sh | ||
sudo NOBLE_HCI_DEVICE_ID=1 node <your file>.js | ||
``` | ||
Roadmap (TODO) | ||
-------------- | ||
## Roadmap (TODO) | ||
@@ -319,4 +432,3 @@ * Mac OS X: | ||
Useful Links | ||
------------ | ||
## Useful Links | ||
@@ -327,6 +439,5 @@ * [Bluetooth Development Portal](http://developer.bluetooth.org) | ||
License | ||
======== | ||
## License | ||
Copyright (C) 2013 Sandeep Mistry <sandeep.mistry@gmail.com> | ||
Copyright (C) 2015 Sandeep Mistry <sandeep.mistry@gmail.com> | ||
@@ -338,1 +449,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
[![Analytics](https://ga-beacon.appspot.com/UA-56089547-1/sandeepmistry/noble?pixel)](https://github.com/igrigorik/ga-beacon) | ||
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
241876
5474
448