Control LIFX Bulb using Spark Core

Introduction

Here I am sharing a project to control LIFX WiFi bulb with :spark: . 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 :spark: 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 :spark: 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.

Sample applications

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).

Installation

  1. Download and Install Node.js from this link
  2. Download the node.js server from https://github.com/krvarma/LIFX_SparkCore and extract
  3. Goto the folder and run npm install. Since it contains the package.json file, it will install all the dependencies
  4. Run node lifx.js
  5. Flash the :spark: with one of the example
  6. Connect LIFX and wait for the bulb to connect to the network

Conclusion

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 :spark: 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 :spark: can blink the bulb or change the color, etc…

Demo Video

Screenshots

Web Page

Web Page

Spark Core Sample Two

Limitations

  1. 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. :spark: 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.

  2. 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.

5 Likes

This is very cool–thanks for sharing!

Did you think about having the Spark core directly control the LIFX buld instead of using a node js server in the middle?

1 Like

That is exactly what my intention @bko, I made only little progress on it. I will share once I am able to detect the bulb and turn on/off.

3 Likes

Anyone managed to do this without the node js bridge?
Unfortunately it’s beyond my ability right now, just thought i’d ask. :slight_smile:

There's a library available in the Web IDE.

See this thread for the discussion :smiley:

Thanks, looks cool, but I think that’s the opposite to what I want. I’d like to control my lifx bulbs using a spark core (i.e.: make a switch using the spark core to control 6 lifx bulbs).

1 Like