Raspberry Pi & RabbitMQ

Looking back on all the Raspberry Pi things I've worked on in the last year, a trend started to emerge. In almost every project I found myself using it as an easy connection to the Internet. Sometimes that involved actually controlling something with the built-in GPIO pins, other times an Arduino might do part of the work and the Pi would simply relay data from the serial port.

As I became familiar with the strengths and weaknesses of the various micro-controllers and single-board computers in my possession, I got comfortable assigning them specific roles based on what they did best. That meant I didn’t spend time fumbling around with an Arduino and some break-out board, trying to get online, just because I was using it to read a few sensors. The Raspberry Pi is much better suited for the network stuff.

After trying out different architectures in a handful of projects you realize some work better than others. I got a lot of mileage out of using cron jobs that would regularly call scripts to collect and send data back to a server with a JSON API. Eventually, as some projects grew, that started to get a little too complicated. I reached a point where I just wanted to control the Raspberry Pi. I wanted an easy way to ask it for something and have it respond.

With that in mind, I created a Python library that uses RabbitMQ messaging called: Pi-Control-Service. Once the service is started, it listens on a queue for messages. When a message is received, the service does some work and sends back another message with a result. So far, it’s been working pretty smoothly.

36 Seasons

For whatever reason, I didn't stumble across nearly as much new music in 2014 as I did in 2013. Maybe 2015 will shape up differently? Anyway, music discovery dry spell aside, I did get an awesome album to close out the year thanks to Ghostface Killah. 36 Seasons tells a different story, with a different vibe, but it's equally as enjoyable as one of my favorites from last year: Twelve Reasons To Die. Every time it goes on, it stays on until the last track is done.

Pi Pin Manager

I took a deep dive into maker culture this year and learned more than I could have ever expected. There is no shortage of problems to solve, no matter how small they may seem, and that played a big role in exposing me to things I wouldn't have encountered otherwise. With each little project I tackled, I found myself coming up with specific ways I liked to solve reoccurring problems. Pi Pin Manger was born out of that.

Each time I did something with Raspberry Pi GPIO I got tired of writing the same things over and over again. After experimenting with a few different approaches to simplifying the process, I finally settled on something I liked using a configuration file written in YAML. Everything each GPIO pin needs to do is defined in a very human-readable way and separated from the project code. Check it out: http://projectweekend.github.io/Pi-Pin-Manager/.

Organizing Cron Jobs with Node.js + Express

While working on a project recently, I needed to write a handful of scheduled tasks to collect or manipulate data. Each task would share some common elements, like connections to MongoDB or RabbitMQ servers, among other things. Ultimately I wanted a single connection to each external service with the tasks using them as needed. Some jobs would be scheduled to run every five minutes so I didn't want them having to connect and disconnect that often. Let's see...

How about using a small web server? All the server has to do is expose API routes on localhost. The logic for various tasks can be organized in the route handler functions. Each Cron job then becomes a simple shell script that curls a local URL. Sounds pretty good to me.

Since I was already using a lot of JavaScript on related projects, I chose to build things with Node.js and Express. This could just as easily have been done with another language or framework. If I were to do this in Python I'd definitely use Flask or Bottle not something big like Django. Micro frameworks are much more flexible.

A full example of how I put this together is on Github: https://github.com/projectweekend/Holly-Jobs. Everything for the web server is found in the /app directory and any script called by a Cron job can be found in /cron.