Popular searches
//

Using a Raspberry PI to control an extreme feedback device

24.7.2013 | 5 minutes reading time

In this article I will show you how to use a Raspberry PI and a Jenkins CI server to control a USB traffic light. I have used the USB traffic light in software projects to display the status of one or multiple Jenkins CI jobs. The traffic light was clearly visible to all team members and stakeholders and everybody knew right away once a build was broken.

pi-case usb-traffic-light

Unfortunately I did not find an affordable USB traffic light, that I could control directly from the Jenkins CI server over the network and that came with software for different operating systems. I was also forced to have it connected to my local computer. Once I left the office and the computer was shut down, the traffic light was turned off.

That problem can be solved using the inexpensive Raspberry PI 🙂

Architecture

The following diagram gives an overview of the architecture:

  1. We will have a script running on the Raspberry PI that constantely polls the status of a configured Jenkins Job
  2. Depending on the status of the Jenkins Job the script updates the USB traffic light

polling

And these are the Prerequisites

Lets go 🙂

Raspberry PI installation

First of all we need to get the Raspberry up and running. Therefore you need to install a bootloader and operating system image on the SD Card. I suggest you use the Raspbian “wheezy” installation.

I was running the installation from my ubuntu computer. When you are using Windows or Mac please check http://elinux.org/RPi_Easy_SD_Card_Setup for information.

Step 1: Download the wheezy image

http://www.raspberrypi.org/downloads

Step 2: Verify and unzip image

Step 3: Prepare the SD Card

Insert the SD Card into your computer, in order to copy the wheezy image onto the card.

Step 4: Copy image to SD Card

Step 5: Prepare Raspberry PI hardware

Once you have copied the wheezy image onto the SD Card you can connect the card to your Raspberry. Add the network cable, tv cable, USB keyboard, your monitor and the Cleware USB traffic light to the Raspberry. After that you can attach the micro USB power supply to startup your Pi.

You should see a blue screen starting up the system. Please follow the instructions on the screen. During the first startup the Raspberry wants to connect to the internet and check for updates. Once you are done you can proceed with the next step.

Step 6: Login to your Raspberry PI

Once you are logged in you can check out the operating system and directory structure. Next you should switch to the root user.

Step 7: Install Clewarecontrol

During the next step we need to install additional software that controls the USB traffic light under Linux. This Software is provided by Folkert van Heusden.

Step 8: Test USB traffic light

First verify that you can find your USB traffic light. It should return the device id. You can use that id later on to control specific traffic lights, in case you have multiple attached to your Raspberry PI.

In case the device list is empty you should reboot the raspberry.

Once the software is installed correctly ou should be able to control the red, yellow and green light:

Step 9: Connect Jenkins Build Job and USB Traffic light

In the last step we need to configure a script that checks the status of a Jenkins CI Job. You can use the following shell script for that. Just fill out your properties on top of the script and start it on the Raspberry PI command line.

I posted the script as a Gist on Github so you do not have to manually create the script on your PI. Link: https://gist.github.com/marcelbirkner/6037722/download

Simply follow these instructions:

In the next step you need to configure the shell script that checks your Jenkins job status and controls the usb traffic light.

  • set USER
  • set PASSWORD
  • set JENKINS_SERVER
  • set JOB_NAME
  • set DEVICE_NO

Once you have configured these parameters on top of the shell script you can start the script. It should poll your jenkins and update the traffic lights.

Start the configured jenkins job and see what happens 🙂

You can find more sample script for bash, ruby and clojure on the following site:

https://github.com/codecentric/cleware-build-traffic-light-jenkins-connector

The Final Result

Here are some pictures what my setup looks like.

2013-07-20 14.41.05 2013-07-20 14.05.59 jenkins-screenshot

Have fun with your new extreme feedback device and feel free to share your ideas and experiences 🙂