contact Me

Use the form on the right to contact me.

You are welcome, to contact me regarding the topics of this page, my open source projects, or my work. Please use the contact form and leave a valid email address for me to respond to.

Thank you.

Egidestr. 9
44892 Bochum
Germany

The L8 Smartlight and a Nodejs SDK

/brain/dump

Random thoughts, bright ideas and interesting experiments. In short the ramblings of a fulltime nerd.

 

The L8 Smartlight and a Nodejs SDK

Jakob Westhoff

Update: The API does now support Promises. You may freely chose which kind of asynchronous handling you want to use.

Update: The full documentation of the API is now available.

Yesterday my L8 Smartlight finally arrived. After having backed it on Kickstarter about 2 years ago, I had already given up on ever holding the final product in my hands. Even though the team behind the L8 had massive problems with it they delivered in the end.

The Hardware

At first sight the L8 is of high quality. The hardware leaves a very nice impression. Its seems to be a solid product. There are some people, which seem to have gotten a bad batch, as they say their devices burned out just after using it a couple of minutes. Fortunately I don't seem to have gotten one of those faulty lights. As far as the hardware goes the L8 is nicely done. The software side however unfortunately looks quite different.

iOS and Android Integration

The L8 can be paired with iOS and Android devices via Bluetooth LE. After the pairing is completed it shows all different kinds of notifications once EMail, WhatsApp messages, or other kind of communication is received. This part actually works quite well. Even though I only tested it with my iPhone. Therefore I can't say anything about the Android support. The shipped App for iOS surely wouldn't win a design award, but it is functional and does what it has been built for.

Development Resources

As a developer I of course wanted to fiddle around with the L8, taking a look at what I could do with it, that nobody else had thought of yet ;). I therefore headed over to the L8 Github repository to check out, what kinds of SDKs were available. Unfortunately I wasn't really happy with what I found there. There is an iOS and an Android SDK. Even though those have been used to create the applications available for each of the platforms, they didn't seem to be very stable nor sophisticated. Furthermore I didn't want to write a iOS or Android application, but something, that could run on a desktop machine, or a Raspberry Pi. I searched for something like a low level C SDK, but didn't find anything. My eyes fell upon a JavaScript SDK. I thought now we are talking and took a look at it. To my regret this SDK was based on the SerialPort API, that is offered by Chrome to Chrome-Apps. Furthermore the library code seemed to have been written in a real hurry. I thought to myself: Okey there you have a starting point. Try to adapt this SDK to nodejs.

My Nodejs SDK

After an hour of back and forth I realized, that this endeavor wasn't going to work. The codebase simply was to much of a mess, to be properly wrapped and integrated into a nodejs environment. Furthermore I didn't really like the API itself. I googled my way through the internet hoping someone might have documented the protocol of the L8 in order to allow me implementing my own SDK without having to reverse engineer everything. Luckily the L8 creators themselves published a protocol specification of what they call SmartLightControlProtocol (SLCP). After reading it I decided to get going implementing my own L8 nodejs SDK called l8smartlight. Even though it is far from being feature complete at the moment, I like what is already possible with it. It took me more time, then I expected to implement the different functionality, as the documentation isn't accurate at all points, which made me reverse engineer parts of the protocol anyways ;). Currently the SDK allows to control of the full LED matrix as well as the SuperLED, to configure orientation, put scrolling text on the L8 as well as to execute some other functionalities. Most of the Command protocol is implemented and encapsulated under a nice and easily usable API. The protocol to query the L8 for information about its various sensors is currently in the works. I hope to push an update soon.

Using a simple snippet like this is all, that needs to be done in order to show splashes of beautiful colors on the LED matrix. Of course only your imagination is the limit :)

var L8 = require("l8smartlight").L8;

var SERIAL_PORT = "/dev/tty.usbmodem1413411";

var l8 = new L8();
l8.open(SERIAL_PORT, null, function(error, response) {
  var colors = [{r: 0, g: 15, b: 15},{r: 15, g: 15, b: 0},
                {r: 0, g: 15, b: 0}, {r: 15, g: 0, b: 0}];
  var currentIndex = 0;

  var next = function() {
    var matrix = Array.apply(null, new Array(8*8)).map(function() {
      return colors[currentIndex];
    });
    l8.setMatrix(matrix, function(error, response) {
      currentIndex = (currentIndex + 1) % colors.length;
      setTimeout(next, 250);
    });
  };
  next();
});

Hopefully you will have as much fun playing with this library and the L8 as I had developing it. The source code is very well documented. Take a look at Library/L8.js, until I got some time writing proper docs and some more examples. The file contains a lot of details about available methods, options and return values. For the future I am planing a promise based API as well, in order to easily manage the callback hell, that comes with all the asynchronous operations. However this API will be optional of course. The SDK is available via npm as well, allowing you to easily consume it in your own projects.

Have fun and stay tuned for updates.