just some thoughts about software and other things I like

LimitlessLED Gem

The LimitlessLED is an all-in-one light bulb that you can control via your wifi network in your house. They are cheap, easy to setup, and have an open API.

The source code for the gem is on Github.

Build Status Dependency Status Code Climate


While the LimitlessLED Smart Lights are really cool on their own, the open API makes them much more interesting. It's almost hard to not have tons of fun ideas. Maybe you're an asshole and want all the lights in your house to blink when someone tweets at you. Maybe you just want the lights near your developers in your startup to flash red when a build fails?

The problem with this is that the API itself is a little low-level and leaves a lot to be desired. The device needs a higher level of abstraction, for example changing the color of the lights requires translating the color in the HSL color model to a single value with a range of 0-255. See the chart below to see how HSL is modeled spatially.

If you're not familiar with this color model, HSV stands for hue, saturation, and value, and is also often called HSB (B for brightness).

Because of these domain specific challenges (using UDP, handling byte-code, understanding the HSV color model, etc.) in developing for the LimitlessLED I decided to abstract control of the unit in Ruby as a gem, this way you can integrate it with your application or just build something for fun.

Remember, because we are using UDP on your LAN, you'll need to implement port forwarding to the LimitlessLED Bridge (which is like a router but also also runs TCP/IP alongside a UDP server) if you want your lights to be accessible over the internet.

The LimitlessLED connects to a bridge unit which can control up to 400 bulbs. The bridge itself runs both TCP/IP and UDP. Our gem uses UDP, we chose this over TCP because of its extremely low latency.

The documentation is pretty clear and straightforward. Here you'll find some details on how to issue commands to the bridge over UDP. UDP commands are 3 bytes where the first byte tells the bridge what command to run, the second byte is a parameter if the specified command requires one, otherwise it's just 0x00 (decimal: 0). The last byte ends the command and is always 0x55 (decimal: 85).

As an example the bytes 0x42 0x00 0x55 would turn all LimitlessLED Smart lights connected to the bridge on. Where the command 0x40 0x00 0x55, would turn them all to the color purple, because the second byte (0x00), is the value that corresponds to the purple area of the color scale the lights use.

Using the Gem

We've built a Ruby gem for controlling the lights over UDP, here is an example of how to change the color of the lights with our gem.

require 'limitless_led'

# Connect to the bridge
bridge = LimitlessLed::Bridge.new(host: '10.10.100.254', port: 8899)

# Send in hex like this:
bridge.color "#ff0000"

# You can send a triple
bridge.color "#f00"

So those are just some simple things like changing color, but here is an example where we are taking the color of the sky from a live webcam (in our case for Lake Tahoe), and changing the color of the lights to match. This could be taken a step further and the lights could change to a complimentary or other harmonious color (see this chart for more on that).

# Install miro gem first
# https://github.com/jonbuda/miro
require 'miro'
require 'limitless_led'

# Source of image
colors = Miro::DominantColors.new('http://cdn.abclocal.go.com/three/kgo/webcam/tahoecam.jpg')

# Connect to bridge
bridge = LimitlessLed::Bridge.new(host: 'localhost', port: 8899)

# Send send most dominant color from image to the LED
bridge.color colors.to_hex[0]

Lastly, UDP is very fast, you can really hammer the bridge pretty fast, this is one of the advantages of UDP, this allows us to make smooth transitions between the colors, see the following example.

10.times do
  (0..255).each do |int|
    bridge.send_packet "\x40#{ int.chr }\x55"
    sleep 0.005
  end
end

Running the sever

We also built a mock server (just run bin/server) for the bridge. The logger for the server outputs the color of the light, this allows for developers to work on projects without the actual light handy, or do more in-depth debugging. The following is the log output for the command above.

We've really only implemented changing the color of the lights, so there is much more functionality to come.