Profile faxon

I build websites.

    How to Make a Traffic Light Build Indicator

    Objective/Overview

    This Arduino project provide a physical red/yellow/green traffic light style based on continuous integration output from Janky.

    What it does

    Prerequisites / Things you need

    Software:

    Hardware (all links to Amazon):

    How it is done

    Step 0: Setup Janky

    Before digging into the specifics of how this is implemented here is a quick overview of who's talking to what. Everything above the blue dotted line is part of a standard Janky setup. Everything below the blue dotted line is what this writeup will cover.

    Arduino Janky Stop Light

    Step 1: Aggregate Janky Output

    The Arduino program expects a single word in the body of the response, either GOOD, BUILDING or JANKY. Each matches to a light on the Arduino, GOOD => green, BUILDING => yellow, and JANKY => red. We need to provide an HTTP accessible page that provides the worst build status across multiple Janky builds. There are any number of ways to do this, the best solution is probably to extend the Janky rack app.

    I chose to aggregate the build statuses with a google Go application, mostly because I've been looking for an excuse to try the language. It also provides a simple config file for builds to check.

    my Go solution

    Janky outputs a simple html doc that has the latest build status for the projects it's been configured to watch. I could not find any JSON output in the source, so I decided to just parse the HTML output, which makes this solution more fragile. The Go app that I wrote is really simple. It takes a list of url's stored in a text file, fetches those URL's and returns the worst case build status as a single string, GOOD, BUILDING or JANKY. Go makes it pretty easy to return this in a running web server. In production I hooked it up behind an nginx instance.

    Step 2: Arduino

    The Arduino portion of this project pretty simple. It just reads the single line output of the worst build status (GOOD, BUILDING or JANKY) and turns on the appropriate LED. My implementation uses four output lights, red, yellow, greed and a blue light for for error codes. The guts of the client just reads each line from the output and updates the light.

    if (client.connected()) {
      if (client.available()) {
        char c = client.read();
        currentLine += c;
        // clear currentLine when new line reached
        if (c == '\n') {
          currentLine = "";
        }
    
        if ( currentLine.equals("JANKY") ) {
          clear_lights();
          digitalWrite(red, HIGH);
          client.stop();
        }
        if ( currentLine.equals("GOOD") ) {
          clear_lights();
          digitalWrite(green, HIGH);
          client.stop();
        }
        if ( currentLine.equals("BUILDING") ) {
          clear_lights();
          digitalWrite(yellow, HIGH);
          client.stop();
        }
      }
    }
    

    Summary: Using Arduino to show build status for multiple for multiple Janky builds.