8000 GitHub - DucRP/noble: A node.js BLE (Bluetooth low energy) central module · GitHub
[go: up one dir, main page]

Skip to content
DucRPPublic
forked from noble/noble

About

A node.js BLE (Bluetooth low energy) central module

Resources

Stars

0 stars

Watchers

1 watching

Forks

 
 

Latest commit

 

History

361 Commits

Folders and files

Repository files navigation

noble

Gitter

A node.js BLE (Bluetooth low energy) central module.

Want to implement a peripheral? Checkout bleno

Note: Mac OS X and Linux are currently the only supported OSes. Other platforms may be developed later on.

Prerequisites

OS X

Linux (Ubuntu)

  • Kernel version 3.6 or above
  • libbluetooth-dev

Ubuntu/Debian/Raspbian

sudo apt-get install bluetooth bluez-utils libbluetooth-dev

Intel Edison

See Configure Intel Edison for Bluetooth LE (Smart) Development

Install

npm install noble

Usage

var noble = require('noble');

Actions

Start scanning

noble.startScanning(); // any service UUID, no duplicates


noble.startScanning([], true); // any service UUID, allow duplicates


var serviceUUIDs = ["<service UUID 1>", ...]; // default: [] => all
var allowDuplicates = <false|true>; // default: false

noble.startScanning(serviceUUIDs, allowDuplicates[, callback(error)]); // particular UUID's

NOTE: noble.state must be poweredOn before scanning is started. noble.on('stateChange', callback(state)); can be used register for state change events.

Stop scanning

noble.stopScanning();

Peripheral

Connect
peripheral.connect([callback(error)]);
Disconnect or cancel pending connection
peripheral.disconnect([callback(error)]);
Update RSSI
peripheral.updateRssi([callback(error, rssi)]);
Discover services
peripheral.discoverServices(); // any service UUID

var serviceUUIDs = ["<service UUID 1>", ...];
peripheral.discoverServices(serviceUUIDs[, callback(error, services)]); // particular UUID's
Discover all services and characteristics
peripheral.discoverAllServicesAndCharacteristics([callback(error, services, characteristics));
Discover some services and characteristics
var serviceUUIDs = ["<service UUID 1>", ...];
var characteristicUUIDs = ["<characteristic UUID 1>", ...];
peripheral.discoverSomeServicesAndCharacteristics(serviceUUIDs, characteristicUUIDs, [callback(error, services, characteristics));

Service

Discover included services
service.discoverIncludedServices(); // any service UUID

var serviceUUIDs = ["<service UUID 1>", ...];
service.discoverIncludedServices(serviceUUIDs[, callback(error, includedServiceUuids)]); // particular UUID's
Discover characteristics
service.discoverCharacteristics() // any characteristic UUID

var characteristicUUIDs = ["<characteristic UUID 1>", ...];
service.discoverCharacteristics(characteristicUUIDs[, callback(error, characteristics)]); // particular UUID's

Characteristic

Read
characteristic.read([callback(error, data)]);
Write
characteristic.write(data, notify[, callback(error)]); // data is a buffer, notify is true|false
Broadcast
characteristic.broadcast(broadcast[, callback(error)]); // broadcast is true|false
Notify
characteristic.notify(notify[, callback(error)]); // notify is true|false
  • use for characteristics with notifiy or indicate properties
Discover descriptors