In part 1 I walked through getting the Raspberry Pi initially up and running. Once you’re logged in, you can immediately start hooking up sensors and start polling them directly from the command line. However, you’re likely going to want some more software installed for additional tasks. For my fermentation controller, I’ve decided on the following software stack.
Software Stack
All of the data read from sensors along with GPIO state changes will all be recorded in Graphite. Graphite stores the data and provides tools for generating graphs from it. The StatsD server will be responsible for sending data to the graphite server. I’ll be using Node.js for communicating with the sensors and providing a web-based interface to interact with the entire system. The web UI will also use MongoDB for storing additional fermentation data.
Screen
Before starting to install all of the necessary software, it’s a good idea to install the screen program and start it up. Some of the steps can take a long time to complete and if your SSH session gets disconnected, screen will keep the session active. In that case all you need to do is reconnect and run the screen command to reattach to your previous running session.
1 2 3 4 5 6 7 8 9 10 11 |
|
Node.js
There are to ways to install Node.js. You can choose to either install a package via apt-get or to compile it directly from source. While the first option is quick and simple, you’ll get a much older version (currently 0.6.19) than if you build it yourself.
1 2 3 4 5 |
|
Fortunately, the most recent versions of Node.js have support for the Pi’s architecture. So Building from source is a fairly straightforward series of steps and doesn’t require any complex patching steps as it did for older versions. The downside is that it’ll take at least several hours to compile. The following steps should result in a fresh installation of the most recent release version of Node.js.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Graphite
Getting Graphite installed isn’t much more work. Since it is a python application it also takes quite a bit less time than compiling Node.js. However, there is some additional configuration work that has to be done. Graphite is composed of several different components. The backend component is called Carbon. The Carbon server is what StatsD will send its data to. The web accessible interface portion responsible for generating the graphs is known as Graphite. Since this is a web interface, we also need a web server. So, the Apache web server will also be installed during the process. If you’d rather have a more automated procedure itt’s also possible to script most of these steps as in this example.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Graphite comes with a good collection of example configuration files that provide a good set of defaults to get started with. Only a few edits in a few spots are necessary to get going. It’s a good idea to take a look through each configuration file anyway to get an idea of the options that are available.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
At this point you could manually start up the carbon server and connect to the graphite web site. Instead, we’re going to install one more script that will make sure that carbon is started automatically whenever the Pi is booted.
1 2 3 4 5 6 |
|
If everything was successful, you should now be able to access graphite in your web browser. The default Apache configuration assigns the name ‘graphite’ to the website. To be able to access it, you’ll need to map that name to the IP of the Raspberry Pi in your hosts file. On OSX or GNU/Linux platforms you would edit the file /etc/hosts. The file in MS Windows is usually located at C:\Windows\System32\drivers\etc\hosts. The new entry would look similiar to this:
192.168.2.189 graphite
modified to reflect the actual IP of the Pi. After the hosts file has been updated, you should be able to open http://graphite/ in the web browser of your choice. If it worked, you should see the Grahpite graph composer interface. Of course, it’ll be a bit boring still until you start logging some data.
StatsD
StatsD is a small Node.js application and doesn’t require any special installation steps on its own. You could just download the source repository and start running it. However, we’d like to have it automatically start up when the system boots up just like we setup carbon. Fortunately, the StatsD repository includes everything needed to turn the source into a debian package complete with boot scripts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
MongoDB
The last piece of software in our stack is MongoDB. Unfortunately, the stock version doesn’t support the Pi’s architecture. Luckily there are several forks which have added this support. I’ve chosen to use one called mongopi. This is a slightly older version based on 2.1.1, but it should work for our needs on the Pi. This approach also means that we’re compiling from source again. You’ll want to make sure that you’re running screen before you start because MongoDB takes a really long time to build and install – on the order of 12 hours long. Once you hit enter on the scons command, you may just want to leave it to run and check back in on it tomorrow.
1 2 3 4 5 6 7 8 9 |
|
As we did with the other components, we want to make sure that MongoDB starts up during boot. There are also a few directories to be created before mongo can be started.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Conclusion
After going through all of these steps, you’ll have a Raspberry Pi running with Graphite, StatsD, MongoDB, and Node.js. It’s a good idea to try rebooting (shutdown -r now will accomplish this) and make sure that all of the services start up on boot as they’re supposed to. The ps command can be used to show running processes and verify that the services are all running. In part 3 I’ll cover the rest of the hardware components of the project and how to get all of the sensors wired up.