LIFX Java Library

Use Java to talk to your LIFX color light bulbs on your local LAN.

The emirac LIFX Java Library communicates with LIFX bulbs on your LAN. It's a Java archive called "emirac.lifx.jar" that consists of a few objects and interfaces that facilitate discovering bulbs and querying and setting their power, colors, and names. Complete documentation for the API is online here: http://www.emirac.net/lifx/doc

Where To Get It

Examples

Android Example: CopFone!

This is an example app called "CopFone!" that uses the emirac LIFX Java Library. The app consists of three components:
  • FoneReceiver: receives PHONE_STATE broadcasts from Android and calls startService to send the state to a service
  • SettingsFragsActivity: a settings activity which lets the user change a boolean preference (ON or OFF)
  • LifxService: a service which uses emirac.lifx.jar to flash or restore the lights (depending on the phone state) if the preference is ON
The Android app is available here.

You can download the Android Studio source code for this app here: copfone.zip

Android Example: Chromania

This is an example app called "Chromania" that uses the emirac LIFX Java Library to convert sound into light. The app consists of:
  • DiscoveryService: maintains a persistent list ov LIFX bulbs we've seen
  • SettingsFragsActivity: a settings activity which lets the user change parameters
  • AudioLightService: a service which samples mic input, transforms pitch and volume into hue and brightness, and uses emirac.lifx.jar to change bulb color.
The Android app is available here.

RaspberryPi Example: Fire

The video below shows the Fire program running on an RPi and sending many messages to bulbs and discovering a new bulb. During the time the RPi program runs the CopFone app jumps in and sends and receives lots of messages to flash the bulbs from an Android. After CopFone exits the Fire program is still working. When Fire exits it returns the bulbs to their initial state.

This is an example Java program called "Fire" that uses the emirac LIFX Java Library. Fire will run on any Java platform that can do wi-fi. Here it's running on the RPi. Fire consists of two Java classes: Fire1.java and FireTask.java.
  • Fire1: contains the main entry point. Keeps track of the bulbs discovered and their initial conditions. Creates a runnable FireTask for each new bulb and adds it to an ExecutorServce threadPool.
  • FireTask: one FireTask for each bulb. FireTask is a runnable with an infinite loop which changes its bulb's color to make it flicker.
Fire finds every bulb on your local net and makes it flicker like a candle. When it shuts down (via ctrl-C or the "enter" key) Fire resets each bulb to its original color and power state. All the code for fire is below.

The code for Fire1.java:

The code for FireTask.java:


(contact: Jeff))