BLE


Repository| Issues

Bluetooth Low Energy (BLE) is a newer standard for communicating with Bluetooth devices. It's focused on lower cost and power consumption. A number of newer hardware devices come with BLE on-board.

cylon-ble can be used to communicate directly with BLE devices, requesting low-level details such as battery status and generic device info. It can also be used as an adaptor for more complicated modules that control larger-scale devices, such as the Orbotix Ollie.

For more info about BLE click here.

How to Install

Install the module with:

$ npm install cylon cylon-ble

For Ubuntu you must install the following dependency prior to npm install cylon-ble:

$ sudo apt-get install libbluetooth-dev

How to Use

Here's a basic BLE example to get the battery level of a device:

"use strict";

var Cylon = require('cylon');

Cylon.robot({
  connections: {
    bluetooth: { adaptor: 'ble', uuid: '207377654321' }
  },

  devices: {
    battery: { driver: 'ble-battery-service' }
  },

  work: function(my) {
    my.battery.getBatteryLevel(function(err, data) {
      if (!!err) {
        console.log("Error: ", err);
        return;
      }

      console.log("Data: ", data);
    });
  }
}).start();

How to Connect

var Cylon = require('cylon');

Cylon.robot({
  connections: {
    wiced: { adaptor: 'ble', uuid: '207377654321' }
  },

  devices: {
    battery: { driver: 'ble-battery-service' }
  },

  work: function(my) {
    every((1).second(), function() {
      my.battery.getBatteryLevel(function(err, data){
        if (err) {
          console.log(err);
        } else {
          console.log("BatteryLevel:", data);
        }
      });
    });
  }
}).start();

You will need a computer with a hardware adaptor that supports Bluetooth LE, also known as Bluetooth 4.0, or Bluetooth Smart. Also, this module currently only supports OSX and Linux operating systems.

Commands

You can use the cylon-ble modules's included commands to scan for BLE devices, and then to list the various BLE characteristics for a specific device.

Note that you need to install cylon-ble using the -g option, and then run each commands under sudo like this:

$ sudo cylon-ble-scan
Starting scan.
Peripheral discovered!
  Name: 2B-785E
  UUID: cc360e85785e
  rssi: -80

$ sudo cylon-ble-info cc360e85785e
peripheral with UUID cc360e85785e found
  Local Name        = 2B-785E
  TX Power Level    = -10
  Service Data      =
  Service UUIDs     = 22bb746f2ba075542d6f726568705327

services and characteristics:
1800 (Generic Access)
  2a00 (Device Name)
    properties  read, write
    value       32422d37383545 | '2B-785E'
...