The Github lamp

Posted 16.09.2012

Update: This project is now on github: relekang/lumen

My arduino has been collecting dust in a drawer for a while. This weekend I figured why not hook it up with github post-receive hooks and do something cool. The hooks can be set up in the Service Hooks section of a repository's admin page on github. Just add a url to where the site is running and github will send that url a POST request everytime someone pushes a commit to the repository. You can fin more info about post-receive hooks at

About two years ago I rebuilt a IKEA children-lamp to be controllable with high/low digital signals.

The IKEA lamp

I wrote this based on the serial example for the arduino. It turns the lamp on and off according to the commands on, off and blink.

String inputString = "";
boolean stringComplete = false;
int led = 5;

void setup() {
      pinMode(led, OUTPUT);

void loop() {
    if (stringComplete) {
        if(inputString == "on"){
            digitalWrite(led, HIGH);
        } else if (inputString == "off"){
            digitalWrite(led, LOW);
        } else if (inputString == "blink"){
            digitalWrite(led, HIGH);
            digitalWrite(led, LOW);
        } else {
        // clear the string:
        inputString = "";
        stringComplete = false;

void serialEvent() {
    while (Serial.available()) {
        char inChar = (char);
        if (inChar == '\n') {
            stringComplete = true;
        } else {
            inputString += inChar;

The arduino is connected to my mac mini. I have some python code running on the mac to write stuff onto the serial connection between the mac and the arduino. I am using and gunicorn to handle the web requests. The looks like this:

SERIALPORT = "/dev/tty.usbmodemfd121"

class GithubHook:
    def POST(self):
        data = json.loads(web.input().payload)
        print "%s pushed to %s - %s" % (
        return ""

    def GET(self):
        return "Something is wrong"

def send_serial_data(data):
    #open serial port
        ser = serial.Serial(SERIALPORT, 9600)
    except serial.SerialException:


    #close serial port

if __name__ == "__main__":
    app = web.application(urls, globals())

application = web.application(urls, globals(), True).wsgifunc()

To run gunicorn I just run the command:

gunicorn lighthouse_keeper