Skip to content

HeatfanJohn/misfit-bolt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Misfit Bolt Javascript Interface Build status

Thin wrapper around sandeepmistry/noble, that helps Misfit Bolt bulbs discovery, and allows turning them on/off and changing their color and brightness, as well as reading their currently set values. Currently support setting color and brightness via RGBA and HSB.

Prerequisites

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

Setup

npm install misfit-bolt

API Methods

discover

Type static

Arguments

  1. callback (function, optional): function to be invoked once a Bolt is discovered. Takes a Bolt instance as first argument.
  2. uuids (Array, optional): list of Bolt uuid to discover.

Returns

undefined

Example

Bolt.discover(function(bolt) {
  // do something
}, ['29852E52-67A0-490A-BC55-7FAB809AD0C0']);

get

Type static

Arguments

  1. id (string): UUID of a Bolt.

Returns

<Bolt> instance, if found.

Example

let bolt = Bolt.get('29852E52-67A0-490A-BC55-7FAB809AD0C0');
// do something with bolt

remove

Type static

Arguments

  1. id (string): UUID of a Bolt.

Returns

Bool successfully removed

Example

Bolt.remove('29852E52-67A0-490A-BC55-7FAB809AD0C0');

connect

Type instance

Arguments

  1. callback (function)

Returns

instance

Example

bolt.connect(function() {
  // do something
});

disconnect

Type instance

Arguments

  1. callback (function)

Returns

instance

Example

bolt.disconnect(function(){
  // do something
});

on

Type instance

Arguments

  1. callback (function)

Returns

instance

Example

bolt.on(function(){
  // do something
});

off

Type instance

Arguments

  1. callback (function)

Returns

instance

Example

bolt.off(function(){
  // do something
});

get

Type instance

Arguments

  1. callback (function): function invoked when value is available. Return value of String type.

Returns

instance

Example

bolt.get(function(error, value) {
  // do something with value
});

set

Type instance

Arguments

  1. value (String): value to set on bulb. Mostly in the form or RGBA. Also accepts CLTMP 3200,0 or CLTMP 3200,1 (used to toggle on / off). Other undocumented formats might exist.
  2. callback (function)

Returns

instance

Example

bolt.set("228,41,15,10", function(){
  // do something
});

getRGBA

Type instance

Arguments

  1. callback (function): function invoked when value is available. Return value of Array type.

Returns

instance

Example

bolt.getRGBA(function(error, rgbaValue) {
  // do something with rgbaValue
});

setRGBA

Type instance

Arguments

  1. value (Array): value to set on bulb. Should be in the form of [red, green, blue, alpha].
  2. callback (function)

Returns

instance

Example

bolt.setRGBA([228,41,15,10], function(){
  // do something
});

getHue

Type instance

Arguments

  1. callback (function): function invoked when value is available. Return value of Integer type.

Returns

instance

Example

bolt.getHue(function(error, hueValue) {
  // do something with hueValue
});

setHue

Type instance

Arguments

  1. value (Integer): value to set on bulb.
  2. callback (function)

Returns

instance

Example

bolt.setHue(12, function(){
  // do something
});

getSaturation

Type instance

Arguments

  1. callback (function): function invoked when value is available. Return value of Integer type.

Returns

instance

Example

bolt.getSaturation(function(error, saturationValue) {
  // do something with saturationValue
});

setSaturation

Type instance

Arguments

  1. value (Integer): value to set on bulb.
  2. callback (function)

Returns

instance

Example

bolt.setSaturation(12, function(){
  // do something
});

getBrightness

Type instance

Arguments

  1. callback (function): function invoked when value is available. Return value of Integer type.

Returns

instance

Example

bolt.getBrightness(function(error, brightnessValue) {
  // do something with brightnessValue
});

setBrightness

Type instance

Arguments

  1. value (Integer): value to set on bulb.
  2. callback (function)

Returns

instance

Example

bolt.setBrightness(12, function(){
  // do something
});

getState

Type instance

Arguments

  1. callback (function): function invoked when state is available. Return value of Bool type.

Returns

instance

Example

bolt.getState(function(error, state) {
  // do something with state
});

setState

Type instance

Arguments

  1. callback (function): function invoked when state is set.

Returns

instance

Example

bolt.setState(true, function(error, state) {
  // do something with state
});

Example

Bolt = require('.');

// Discover every nearby Bolt
Bolt.discover(function(bolt) {

  // Each time a bolt is discovered, connect to it
  bolt.connect(function() {
    var i = 0,
        colors = [[228,41,15,10],
                  [216,62,36,10],
                  [205,55,56,10],
                  [211,27,76,10],
                  [166,18,97,10]];

    // Change color every 500 ms
    setInterval(function(){
      var color = colors[i++ % colors.length];
      bolt.setRGBA(color, function(){
        // set complete
      });
    }, 500);
  });
});

TODO

  • CLI tool

Notes

About

Misfit Bolt javascript Interface

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%