How to use
Assuming you have a current NodeJS installation, you will need to make sure you have the node-hid module installed (see note below if using Raspberry Pi), and then download the contents of this repository (at a minimum test.js, blync.js, device.js, and package.json) and run the sample
To define new Blynclight devices add the
dev.productId to the list on line 10 in
blync.js (currently supports the standard and mini devices).
To control the light, see sample code in
test.js but essentially you use:
Blync = require('./blync'); var device = Blync.getDevice(0); device.sendCommand(r, g, b,dim,blink);
r,g,bare the red, green, and blue colours (0-255)
dimis a true/false value to set the light to full brightness, or dimmed
blinkis set to 0 for steady, 1 for 'slow', 2 for 'medium', and 3 for 'fast' blinking
By default the Blynclight will remain active and in a steady state provided power is maintained, but the
test.js sample includes a
device.sendCommand to deactivate the light in the exit handler
Running from a web server
web.js file shows an example of a simple NodeJS web server that displays a form and allows you to control the lights.
I actually have it configured on my RaspberryPi to automatically start the web script following a reboot via crontab. I edit crontab using
crontab -e and add the following line to the end of the file:
@reboot /home/pi/blync/auto.sh. That runs the auto.sh script (you may need to adjust paths both in crontab and the script to suit your own configuration, as well as make the script executable
chmod +x auto.sh).
Raspberry Pi / Raspbian
I assume you've already got a current Raspbian build on your RaspberryPi (only tested with a B+), as well as working Node environment, but if not this guide covers most of what you need to know.
Note: As there isn't a predefined binary for Raspberry Pi currently, you will need to build from source and adjust permissions. To build from source see this StackOverflow post and you will need to either adjust the permissions as defined here (you can use the
embrava.rules file in this repository) or run the node script with elevated permissions, eg:
sudo node test.js.
If you want to use the RaspberryPi as a self-contained hotspot to control the Blynclight, see these instructions.
- add additional Blynclight devices (maybe Embrava would like to send me some to test!)
- add the musicControl logic
- only supports first Blynclight device it finds, what if there is >1? (need more devices to test!)
- consolidation and optimization
- make it all a bit more robust
If you make use of this and like it and want to give something back... I wrote a book! :)
This project can be forked from Github. Please issue pull requests from feature branches.
See Licence file in repo, or refer to http://unlicense.org