0.1.0 • Published 10 years ago
bluelight v0.1.0
bluelight
A Bluetooth lamp controller library.
Install
npm install bluelightUsage
const Bluelight = require('bluelight'),
bluelight = new Bluelight();Example projects using this library
- greenlight: a simple web UI + REST API around bluelight
Actions
Start scanning
bluelight.scanFor(5000); // scan for 5 secondsGet list of detected devices
for (let device of bluelight.detectedDevices) {
console.log(device);
}Devices
All these methods return a Promise which resolve when finished executing the command or reject when an error occured.
Enable light
device.enableLight().then(function () {
console.log("Light enabled");
});Disable light
device.disableLight().then(function () {
console.log("Light disabled");
});Set light color
Valid values for the arguments are between 0.0 and 1.0
device.setColor(/*red*/1.0, /*green*/0.0, /*blue*/0.0, /*dimness*/1.0).then(function () {
console.log("Light should be red!");
});Most devices are RGBW and treat pure white as "only light the white LEDs":
device.setColor(1.0, 1.0, 1.0, 0.5).then(function () {
console.log("Light should be dimmed white!");
});Get device information
console.log(device.uniqueId);
console.log(device.friendlyName);Events
See Node.js EventEmitter docs for more info on API's.
Scan stopped
bluelight.on('scanStop', function() {
console.log('Stopped scanning');
});Device discovered
bluelight.on('discover', function (device) {
console.log('Device ' + device.friendlyName + ' discovered');
});The event is emitted only when scanning is started.
Device disconnected
bluelight.on('disconnect', function (device) {
console.log('Device ' + device.friendlyName + ' disconnected');
});Error
bluelight.on('error', function (err) {
console.error(err);
});0.1.0
10 years ago