Here I am sharing a project to control LIFX WiFi bulb with . As of now LIFX cannot be controlled/accessed from outside network/Internet, it can only be accessed from the network in which it is connected to. One method to access it from Internet is to use an intermediate server running on the same network it is connected to and let the server control the LIFX. This server acts as a bridge between the bulb and outside world. LIFX provides some SDKs to control the bulb. There are also lot of reverse engineered SDKs available, one such is the LIFX.js library for node.js.
Communication Between Spark Core and Intermediate server
We can use different methods to communicate between and Intermediate Server, such as MQTT, Sparknode, etc… For this project I used MQTT and Sparknode. There is no reason to use both, but just for exploring I used both MQTT and Sparknode.
The project works using MQTT as message broker. The uses this MQTT Library by Chris Howard to connect to the server and publish messages. The node.js server use this MQTT Library by Adam Rudd. For controlling LIFX bulb I am using the LIFX.js library by Kevin Bowman (magicmonkey). I am using
Eclipse MQTT Sandbox as MQTT Server. I have this node.js server running on my Raspberry PI which is connected to the same network to which the LIFX is connected.
There are two samples, one is the to play with the colors, turn on, blink, etc… For this sample I am using both MQTT and Sparknode. Both achieve the same results but with different ways. The second example uses TSL2561 Light sensor to watch the light level and turn the LIFX red when it is below a particular level and green when above the level.
The first sample comes with a Web Page to control the bulb. You can use this web page to set the color, turn on/off and blink the bulb (don’t forget to replace the deviceid and accesstoken with actual values).
- Download and Install Node.js from this link
- Download the node.js server from https://github.com/krvarma/LIFX_SparkCore and extract
- Goto the folder and run
npm install. Since it contains the package.json file, it will install all the dependencies
- Flash the with one of the example
- Connect LIFX and wait for the bulb to connect to the network
Simply controlling the bulb from outside network is not that exciting, but Spark Core can do a lot of amazing things and controlling LIFX from is good idea. We can use the LIFX as a notification device, for example monitoring the temperature of a room and if the temperature is not within the limit can blink the bulb or change the color, etc…
Spark Core Sample Two
In this sample I am considering only a single LIFX bulb, when there are more than one, the application can easily changed to support multiple bulbs or a group of bulbs. try to get how many lights and groups are connected and fetch the data from node.js server. After this information retrieved we can control individual bulb.
The lifx.js library does not provide methods to retrieve current color of the bulb. This requires some amount of work to understanding the protocol involved using Wireshark or similar tools and implement in the library.