2.0.1 • Published 9 years ago

misfit-bolt v2.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
9 years ago

Misfit Bolt Javascript Interface Build status

Implementation of sandeepmistry/noble-device, that helps driving a Misfit Bolt LED bluetooth bulbs.

Largely inspired by fayep's Python implementation, and sandeepmistry's YeeLight Bluetooth implementation.

Based on Yeelight Blue Message Interface specifications.

Features

  • Control of color via RGBA and HSB schemes.
  • Control of state, with in-bulb persistence of last color set, and in-app persistence of last brightness set.
  • Control of gradual effect transition (progressive or immediate).
  • Control of the bluetooth name of the bulb.

Prerequisites

To connect to the Misfit Bolt, you need BLE capabilities. See sandeepmistry/noble prerequisites for more details.

Setup

npm install misfit-bolt

Developer

npm run lint
npm run doc-lint
npm run doc-gen
npm test

API

Bolt

Parameters

  • peripheral

setRGBA

Set RGBA values of the bolt.

Parameters

  • rgba Array<number> Red (0 to 255) / Green (0 to 255) / Blue (0 to 255) / Alpha (0 to 100) values
  • done ?SimpleCallback completion callback

Examples

bolt.setRGBA([255, 0, 0, 10], function(error) {
  console.log('Bolt now set to red !');
});

Returns Bolt

getRed

Retrieve Red value of the bolt.

Parameters

  • done NumberGetterCallback completion callback

Examples

bolt.getRed(function(error, red) {
  console.log('Current Red value is: ', red);
});

Returns Bolt

setRed

Set Red value of the bolt.

Parameters

  • red number Red value (0 to 255)
  • done ?SimpleCallback completion callback

Examples

bolt.setRed(10, function(error) {
  console.log('Red is now set to 10');
});

Returns Bolt

getGreen

Retrieve Green value of the bolt.

Parameters

  • done NumberGetterCallback completion callback

Examples

bolt.getGreen(function(error, green) {
  console.log('Current Green value is: ', green);
});

Returns Bolt

setGreen

Set Green value of the bolt.

Parameters

  • green number Green value (0 to 255)
  • done ?SimpleCallback completion callback

Examples

bolt.setGreen(10, function(error) {
  console.log('Green is now set to 10');
});

Returns Bolt

getBlue

Retrieve Blue value of the bolt.

Parameters

  • done NumberGetterCallback completion callback

Examples

bolt.getBlue(function(error, blue) {
  console.log('Current Blue value is: ', blue);
});

Returns Bolt

setBlue

Set Blue value of the bolt.

Parameters

  • blue number Blue value (0 to 255)
  • done ?SimpleCallback completion callback

Examples

bolt.setBlue(10, function(error) {
  console.log('Blue is now set to 10');
});

Returns Bolt

getAlpha

Retrieve Alpha value of the bolt.

Parameters

  • done NumberGetterCallback completion callback

Examples

bolt.getAlpha(function(error, alpha) {
  console.log('Current Alpha value is: ', alpha);
});

Returns Bolt

setAlpha

Set Alpha value of the bolt.

Parameters

  • alpha number Alpha value (0 to 100)
  • done ?SimpleCallback completion callback

Examples

bolt.setAlpha(10, function(error) {
  console.log('Alpha is now set to 10');
});

Returns Bolt

getHSB

Retrieve Hue, Saturation and Brightness values of the bolt in the form of an Array of Integers.

Parameters

  • done NumbersGetterCallback completion callback

Examples

bolt.getHSB(function(error, hsb) {
  console.log('Current HSB values are: ', hsb);
});

Returns Bolt

setHSB

Set HSB values of the bolt.

Parameters

  • rgba Array<number> Hue (0 to 360) / Saturation (0 to 100) / Brightness (0 to 100) values
  • done ?SimpleCallback completion callback

Examples

bolt.setHSB([0, 100, 10], function(error) {
  console.log('Bolt now set to red !');
});

Returns Bolt

getHue

Retrieve Hue value of the bolt.

Parameters

  • done NumberGetterCallback completion callback

Examples

bolt.getHue(function(error, hue) {
  console.log('Current Hue value is: ', hue);
});

Returns Bolt

setHue

Set Hue value of the bolt.

Parameters

  • hue number Hue value (0 to 360)
  • done ?SimpleCallback completion callback

Examples

bolt.setHue(10, function(error) {
  console.log('Hue is now set to 10');
});

Returns Bolt

getSaturation

Retrieve Saturation value of the bolt.

Parameters

  • done NumberGetterCallback completion callback

Examples

bolt.getSaturation(function(error, saturation) {
  console.log('Current Saturation value is: ', saturation);
});

Returns Bolt

setSaturation

Set Saturation value of the bolt.

Parameters

  • saturation number Saturation value (0 to 100)
  • done ?SimpleCallback completion callback

Examples

bolt.setSaturation(10, function(error) {
  console.log('Saturation is now set to 10');
});

Returns Bolt

getBrightness

Retrieve Brightness value of the bolt.

Parameters

  • done NumberGetterCallback completion callback

Examples

bolt.getBrightness(function(error, brightness) {
  console.log('Current Brightness value is: ', brightness);
});

Returns Bolt

setBrightness

Set Brightness value of the bolt.

Parameters

  • brightness number Brightness value (0 to 100)
  • done ?SimpleCallback completion callback

Examples

bolt.setBrightness(10, function(error) {
  console.log('Brightness is now set to 10');
});

Returns Bolt

getState

Retrieve State value of the bolt.

Parameters

  • done BooleanGetterCallback completion callback

Examples

bolt.getState(function(error, state) {
  console.log(`Bolt is ${state ? 'on' : 'off'}`);
});

Returns Bolt

setState

Set State value of the bolt.

Parameters

  • state boolean State value
  • done ?SimpleCallback completion callback

Examples

bolt.setState(true, function(error) {
  console.log(`Bolt is now on !`);
});

Returns Bolt

getGradualMode

Retrieve Gradual Mode value of the bolt. Indicates whether transition between states is progressive or immediate.

Parameters

  • done BooleanGetterCallback completion callback

Returns Bolt

setGradualMode

Set Gradual Mode value of the bolt.

Parameters

  • gradualMode boolean Gradual Mode value
  • done ?SimpleCallback completion callback

Returns Bolt

getName

Retrieve Name value of the bolt (as visible by the Bluetooth client).

Parameters

  • done StringGetterCallback completion callback

Returns Bolt

setName

Set Name value of the bolt.

Parameters

  • name string Name value
  • done ?SimpleCallback completion callback

Returns Bolt

getRGBA

Retrieve Red, Green, Blue and Alpha values of the bolt in the form of an Array of Integers.

Parameters

  • done Function completion callback
  • done NumbersGetterCallback completion callback

Examples

bolt.getRGBA(function(error, rgba) {
  console.log('Current RGBA values are: ', rgba);
});

Returns Bolt

init

Starts the discovery loop. Loop consist in stopping and starting the Bolt discovery process every DISCOVERY_LOOP_MS. This is to paliate a potential issue with Noble device that becomes stale after a few hours and loose connection with connected bolt / stop detecting previously disconnected bolts.

Examples

Bolt.init(function(error, rgba) {
  console.log('Current RGBA values are: ', rgba);
});

get

Retrieve an bolt from internal registry.

Parameters

Examples

let bolt = Bolt.get('2312AC5C08E348699B0199458AC644BD');
bolt.setState(true, function() {
  ...
});

Returns Bolt?

remove

Remove an bolt from internal registry.

Parameters

Examples

let bolt = Bolt.remove('2312AC5C08E348699B0199458AC644BD');

Returns boolean

SimpleCallback

Simple completion callback

Parameters

  • Error ?Error while performing async operation

NumbersGetterCallback

Numbers getter completion callback

Parameters

NumberGetterCallback

Number getter completion callback

Parameters

  • Error ?Error while performing async operation
  • Value ?Number retrieved

BooleanGetterCallback

Boolean getter completion callback

Parameters

  • Error ?Error while performing async operation
  • Value ?Boolean retrieved

StringGetterCallback

String getter completion callback

Parameters

  • Error ?Error while performing async operation
  • Value ?String retrieved

TODO

  • CLI tool

Notes

  • PRs welcomed!
2.0.1

9 years ago

2.0.0

9 years ago

1.3.2

9 years ago

1.3.1

9 years ago

1.3.0

9 years ago

1.1.1

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.0.6

9 years ago

1.1.0

9 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago