A Raspberry Pi Build Light for TeamCity in Mono
After I bought my Raspberry Pi I went through a little period of uncertainty that most other owners have, asking myself “how do I make this thing useful?” It didn’t take long before one of my colleagues created a GitHub repository for a little project that had been sitting around for a while – TeamFlash.
TeamFlash is a build light client app for TeamCity. It monitors the build server to find the status of the latest build and flashes a light in a different colour depending on that status. Having a little bit of electronics know-how, I wanted to see if I could make my Raspberry Pi into a standalone build light.
First up, I knew there had to be someone that’s interfaced with the GPIO ports. Within a few seconds of deciding to search I stumbled upon the RPi Low-level peripherals page. This has a sample of driving the GPIO using C# linking to the RaspberryPi.Net GitHub repository. It has one moving part – Mike McCauley’s BCM2835 library. Brilliant! Now to get it working…
The RapsberryPi.Net README has instructions on how to compile the BCM2835 library into a statically linked library named libbcm2835.so. To use GPIO from Mono I simply:
- Compiled the BCM2835 library
- Compiled the RaspberryPi.Net project
- Took the output of both and added them to my Dependencies folder
- Added RaspberryPi.Net.dll to my project as a reference
- Added libbcm2835.so to my project as a linked file and changed its build action to Copy if newer
Now I can write code like:
var led = new GPIOMem(GPIO.GPIOPins.GPIO01); led.Write(true); Thread.Sleep(1000); led.Write(false);
Running TeamFlash on YOUR Pi
Here’s how you can get TeamFlash working on your Raspberry Pi.
Step 1 – Wiring it up
I’ve got some standard LEDs from an old Arduino kit, so I’ve hooked each of those in serial with a 330 Ohm resistor to ensure the forward current is within the correct range.
Step 2 – Boot Raspbian
Go to http://www.raspberrypi.org/downloads and get the latest release of Raspbian. Follow the instructions and get it up and running.
Step 3 – Install the Required Components
To get it all going you’ll need to install mono. If you want to build it on the Pi, install git and mono-complete:
sudo apt-get install git sudo apt-get install mono-complete
Otherwise the mono-runtime will suffice:
sudo apt-get install mono-runtime
Step 4 – Get TeamFlash
Again, if you want to compile the app on the Pi:
git clone https://github.com/ducas/TeamFlash.git cd TeamFlash xbuild
Otherwise you can clone the repository and compile it on your desktop/laptop and just move the output (contents of TeamFlash/bin/Debug) around on a USB key.
Step 6 – Configure TeamFlash
Edit the serverUrl, username and password values in TeamFlash.exe.config (in the output directory of the build – TeamFlash/bin/Debug). If you’re looking for an easy way to do this on the Pi, try using nano:
When using nano, simply change the appropriate values and hit Ctrl + X to exit – you will be prompted to save.
Step 7 – Run TeamFlash
sudo mono TeamFlash.exe
Step 8 – Profit!
And that’s it! When your build is:
- Good – the green light will stay lit
- Broken – the red light will flash on and off
- Investigating – the red and yellow lights will flash sequentially