Ionode - Control your ION lamp from Node!
So we heard you've got an ION. And perhaps you want to control that ION from your PC, Raspberry Pi, or legendary Gibson. Now is your time to shine.
Getting Started
First off, make sure you're using a Bluetooth 4.0 compatible adapter with your computing device of choice. If you're looking for recommendations, we've tested with this guy extensively: http://www.iogear.com/product/GBU521/ You'll also need to ensure that your user has permission to interact with the Bluetooth adapter. If you're lazy, feel free to run your node scripts with sudo.
Installation
First, you'll need a recent version of Node.js installed on your system. If you're setting Node.js up on your Raspberry Pi, we recommend following the guide here:
https://learn.adafruit.com/raspberry-pi-hosting-node-red/setting-up-node-dot-js
Once you've got Node.js up and running, it's as simple as...
sudo apt-get install bluetooth bluez-utils libbluetooth-dev
mkdir ion && cd ion && npm install ionode
sudo node node_modules/ionode/examples/basic/set_color_loop.js
Basic usage
var ionode = ;// creates an ION object that will connect to the ION named 'ion'var ion = ionode; ion; ion;
Events
ION objects inherit from EventEmitter. The following events can be captured.
var ion = ionode; // when ION is seen, this is calledion; // when ION first connects, but before it's ready (initialized) this is calledion; // ION disconnectedion; // ionode is currently attempting to reconnect to IONion; // a general ION error occurredion; // called when ION is tapped and changes moodsion; // called when ION completes initialization and is ready to be controlledion; ion;
Connection
After creating your ion object using 'createLamp', simply call connect.
ion;
Disconnecting is achieved as one would imagine.
ion;
ion.getName()
Returns ION's current name (if valid).
ion.isConnected()
Returns true/false if ION is connected (but not necessarily ready).
ion.isReady()
Returns true/false if ION is ready to control.
ion.setAutoReconnect(autoReconnect)
If autoReconnect is true, ionode will automatically try to reconnect if ION becomes disconnected.
ion.renameDevice(newName, [callback])
Give the specified ION a new name. Callback returns 2 parameters:
- error (null if no error)
- new name (the name just set)
ion
ion.setMood(moodName, callback)
Sets the mood to the mood name provided. Callback returns 2 parameters:
- error (null if no error)
- new mood name (the mood just set)
ion
See the end of this document for all possible moods.
ion.setMoodConfig(moodName, optionName, [callback])
Used for configs that have no value to be set. For instance, the Light mood supports several of these configs. Callback consists of only an error parameter (null if no error).
ion;
See the end of this document for all possible mood configs.
ion.setMoodConfig(moodName, optionName, value, [callback])
Used for configs that expect a value to be set. Callback consists of only an error parameter (null if no error).
ion;
See the end of this document for all possible mood configs.
ion.setMoodConfig(moodName, optionName, value1, value2, [callback])
Currently only used for setting color of a mood. The first value is hue (0-360) with the second being saturation (0-255). Callback consists of only an error parameter (null if no error).
ion;
See the end of this document for all possible mood configs.
ion.getMoodConfig(moodName, optionName, [callback])
Returns the current value of the mood config. Callback returns 2 parameters:
- error (null if no error)
- new mood name (the mood just set)
ion
ion.getRotation(callback)
Returns the current list of moods in the ION's rotation list (which can be modified via the mobile app). Callback consists of 2 parameters:
- error (null if no error)
- array of mood names
ion.saveMoodConfigs([callback])
Stores the current mood's configs to flash memory. After saving, power cycling ION will result in the same state of the mood being restored. Callback consists of only an error parameter (null if no error).
ion
ion.restoreCurrentMoodConfigsToDefault([callback])
Returns the current mood's configs back to the factory default and commits to flash. Callback consists of only an error parameter (null if no error).
ion
Raw Mode
Raw mode allows you to manipulate each pixel to your heart's content. Ionode uses an internal buffer to hold onto LED state. Only after calling setRawShow() will your changes appear (unless you use setRawClearAll or setRawFillColor, those update immediately).
ion.setRawLED(ledIndex, {r: ?, g: ?, b: ?})
ledIndex can range between 0-39. Each 10 indicies corresponds to a vertical row of LEDs on ION, for a total of "4 sides".
The second parameter must be an object containing an r, g, and b value.
// the lonely red pixelion;
ion.setRawShow([callback])
After using setRawLED(), your changes can be sent and displayed on your ION by using setRawShow(). Callback consists of only an error parameter (null if no error).
ion;
ion.setRawClearAll([callback])
This call will set all LEDs to the 'off' state and immediately update ION. Callback consists of only an error parameter (null if no error).
ion;
ion.setRawFillColor({r: ?, g: ?, b: ?}, [callback])
This call will set all LEDs to the rgb values specified and immediately update ION. Callback consists of only an error parameter (null if no error).
ion;
ion.beginWeatherUpdates(latitude, longitude)
Tells ionode to begin sending weather data to ION every 15 minutes for the Weather and Thermometer moods.
ion;
ion.showNotification(notificationName, hue, brightness, saturation, speed, duration, sticky, [callback])
Displays a notification on ION. Callback consists of only an error parameter (null if no error). Parameters are as follows:
- notificationName ('halo', 'spin', or 'glow')
- hue (0-360)
- brightness (0-255)
- saturation (0-255)
- speed (0-255)
- duration (0-10) seconds
- sticky (true/false) if the notification must be acknowledged by tapping the top or calling clearNotification()
// a friendly green bouncing discion;
ion.clearNotification([callback])
Clears a sticky notification (if active). Callback consists of only an error parameter (null if no error).
ion;
Mood List
- off
- light
- flame
- digitalrain
- rainbow
- weather
- thermometer
- hourglass
- lava
- lines
- plasma
- sparkle
- spiral
- fireworks
- strobe
- pulse
- rave
- whirlpool
- volume
Mood Config options
Off
- n/a
Light
- candle (no parameters)
- incandescent (no parameters)
- fluorescent (no parameters)
- bluesky (no parameters)
- sunlight (no parameters)
- brightness (0-255)
- color (0-360 hue, 0-255 saturation)
- lowglow (0-disabled, 1-enabled)
Flame
- color (0-360 hue, 0-255 saturation)
- inferno (0-disabled, 1-enabled)
- enablesound (0-disabled, 1-enabled)
Light
- candle (no parameters)
- incandescent (no parameters)
- fluorescent (no parameters)
- bluesky (no parameters)
- sunlight (no parameters)
- brightness (0-255)
- color (0-360 hue, 0-255 saturation)
- lowglow (0-disabled, 1-enabled)
DigitalRain
- color (0-360 hue, 0-255 saturation)
- speed (0-255)
Rainbow
- speed (0-150)
- brightness (0-255)
- reverse (0-disabled, 1-enabled)
Weather
- forecast (0-disabled, 1-enabled)
Thermometer
- forecast (0-disabled, 1-enabled)
Hourglass
- time (0-65535 seconds)
- color (0-360 hue, 0-255 saturation)
Lava
- color (0-360 hue, 0-255 saturation)
- speed (0-255)
Lines
- color (0-360 hue, 0-255 saturation)
- speed (0-255)
Plasma
- color (0-360 hue, 0-255 saturation)
- speed (0-150)
- soundenabled (0-disabled, 1-enabled)
Sparkle
- color (0-360 hue, 0-255 saturation)
- speed (0-150)
- sparklebrightness (0-255)
Spiral
- color (0-360 hue, 0-255 saturation)
- speed (0-255)
- brightness (0-255)
Fireworks
- dominantcolor (0-360 hue, 0-255 saturation)
- enablecolor (0-disabled, 1-enabled)
- speed (0-255)
- frequency (0-255)
- soundenabled (0-disabled, 1-enabled)
Strobe
- color (0-360 hue, 0-255 saturation)
- colorenabled (0-disabled, 1-enabled)
- interval (0-255)
Pulse
- speed (0-255)
- soundenabled (0-disabled, 1-enabled)
Rave
- speed (0-255)
- dominantcolor (0-360 hue, 0-255 saturation)
- bassboost (0-disabled, 1-enabled)
Whirlpool
- speed (0-255)
- dominantcolor (0-360 hue, 0-255 saturation)
- bassboost (0-disabled, 1-enabled)
Volume
- n/a