We wish you a HTTP Christmas 🎶

The wiring tutorial got me up and running with some Python code, but I was keen to build out a full lighting interface via a HTTP server using Node.js. I’m not very familiar with the WS2811 chip found in my string of LEDs, and didn’t feel like learning how to deliver the data in the correct format (see datasheet: https://cdn-shop.adafruit.com/datasheets/WS2811.pdf). Thankfully, someone much smarter than me has built and open-sourced a Node.js / Raspberry Pi interface for this chip already:

With a simple npm installation, I was able to talk to the lights via my code. All I needed to do now was set up a HTTP server (I opted for express , but there are plenty of other great options), build out some routes, and start controlling my lights. The API runs on port 2811 and provides the following core HTTP routes:

/pixels/brightness — for controlling the brightness of the string of lights

— for controlling the brightness of the string of lights /pixel/:pixelId — for controlling the colour value for a specific LED

— for controlling the colour value for a specific LED /pixels — for controlling the colour value of many LEDs at once

— for controlling the colour value of many LEDs at once /tree — for getting the layout of the tree (depending on how the lights are placed on a physical tree)

— for getting the layout of the tree (depending on how the lights are placed on a physical tree) /mode/:mode — for controlling the various modes (static, random, and cycle)

— for controlling the various modes (static, random, and cycle) /connect — for initialising the connection to the lights via the web UI

During the development process, I found myself working away from the LEDs themselves. This made it difficult to understand the physical effects of the changes I was making. To combat this, I abstracted out the WS2811 connection into a renderers layer, and created two interfaces for rendering out the pixel data. One, to the WS2811 LED lights, and one to my console, for easy debugging.