Raspberry Pi Fermentation Temp Controller I: cron jobs 1 and 2

This is the first of a handful of posts about getting my fermentation temperature controller up and running.  As I indicated before, there are three python scripts on the Raspberry Pi that make this all work.

For those that don’t know, the Raspberry Pi is a small computer that is about the footprint of a credit card.  It isn’t very powerful, but you don’t need power to do this temperature control.  One thing you DO need for this is called GPIO, or General Purpose Input/Output.  These can be used as switches in code.  There are many ways to use these, but the easiest (in my opinion) is using Python.

2015-05-30 10.19.23

Raspberry Pi connected to a breadboard.

My current setup is with the Raspberry Pi connected to a breadboard, which is a device that allows solder-free connections (solder is somewhat permanent and soldering parts to a PCB is a lot of work).  In the image above, the ribbon cable connects to all the GPIO pins on the Raspberry Pi, and specific pins are being used to connect to a temperature sensor and to a light emitting diode (LED).

The two parts of code are to check the temperature and determine if the temperature has gone too low (the Emergency Stop Script), and the other is to send the temperature to a server (the API Send Script).

Emergency Stop Script

This is the check script.  It checks the temperature and shuts off the GPIO output if the temperature is at or below 32.  Two things to note on this, one is that if this temperature sensor is just in the chamber, the beer will probably be a degree or two warmer (unless it stays at 32 for a while).  The other thing to note is that if you are making eisbock, you should probably change or disable this script.

The script above should be set in the cron manager (crontab -e) to run every minute:

*/1 * * * * sudo python /home/pi/source/pyTemp/pyECheck.py > /home/pi/source/pyTemp/pyECheck.log

The code above has it run every minute (the */1).  The path to the script on my Raspberry Pi is /home/pi/source/pyTemp/pyECheck.py, and the output log file is /home/pi/source/pyTemp/pyECheck.log.  Note the use of sudo on this script – or “superuser do”.  This runs the script as a fully privileged user, which is required to use the GPIO pins.

API Send Script

This is the script to send the data to a server.  There are a few things that need to be changed.  One is that you need to generate an encryption key that will be used on the Raspberry Pi and the web server to encrypt and decrypt the data.  This is almost overkill, but it ensures that it cannot be screwed with. The other thing that needs to be changed is the server address.  These are both at the top of the file.

This script should not be run every minute (that’s what we’d call overkill).  I use every 10 minutes, although it could be less often.

*/10 * * * * sudo python /home/pi/source/pyTemp/pyTemp.py > /home/pi/source/pyTemp/pyTemp.log

The next part of this will be either the actual Raspberry Pi connections or the PHP server backend.  But either way, likely both are coming within the next few weeks although regular programming may be interrupted by a brew day report.