Lowering the price w/ ESP8266
avoiding pi-poverty
Gabe // Sept. 27, 2015

After the fourth install I realized I would run out of budget space fairly quickly if I kept on using a raspberry PI and its assorted accessories for each install. I found a bin that could be flashed to an esp8266 and recieve udp packets for color data on a ws2812 strand; Perfect.

It came with a small C binary with example code to write simple patterns over UDP which while I could call wholesale from twisted, would get hairy fairly quickly. After a quick read I put together an output plugin converted my internal array format into buffers to be sent to the esp8266.

class ESPDevice(BaseDevice):
    def __init__(self, addrs=[], port=7777):
        self.addr = addrs
        self.port = port
        self.socket = socket.socket(socket.AF_INET,  socket.SOCK_DGRAM) # UDP
    def write(self, values):
        chunked = chunks(values, 3)
        # convert list from RGB to GRB internally
        # yay code reuse
        filt = RGBtoGRBLambentOutputFilter()
        filtered = [filt.do_filter(i) for i in chunked]
        values = list(itertools.chain.from_iterable(filtered))
        structd = struct.pack('B'*len(values), *values)
        for a in self.addr:
            self.socket.sendto(structd, (a, self.port))
Device Abstraction

This output module is instantiated with a list of IP addresses that are injected into the service from the environment, and supports writing UDP packets to multiple devices. This is useful for tileable patterns that may need to be repeated or more realistically the area behind my speaker grilles.

At this time my fixed cost-per install has gone down from $50+LEDs+Power to $3+LEDs+Power. Which means I can expand rapidly...