Tweeting beer temperature sensor – make your home brew more geeky

Photo credit: St0rmz/Flickr


Tweeting beer temperature sensor

Today’s post will be all about my idea for a tweeting beer temperature sensor!

Few weeks back I started brewing my own beer. It was really great fun and I plan to make some more, in fact my next batch will be a lovely vanilla infused stout.

When reading about brewing stout, I’ve found out that it needs a fairly high fermentation temperature of around 21C. I thought that the best way to keep my beer at this temperature, would be to use a fish tank heater! Dedicated beer heating equipment can be really expensive, so I am planning to stick the fermentation vessel in a nice, warm water bath which will be monitored by the tweeting beer temperature sensor!

Black Hole Stout

I decided to use a Raspberry Pi and a waterproof 1wire DS18B20 temperature sensor in my project. The latest distribution of Raspbian (a Debian based Linux distribution) has 1wire kernel modules already in the system, so I didn’t have to worry about any additional compilation.

To start with, the w1 kernel modules need to be added:

[email protected] ~ $ sudo modprobe w1_therm
[email protected] ~ $ sudo modprobe w1_gpio

If everything worked ok, we should find the temperature probe in /sys/bus/w1/devices/

[email protected] ~ $ ls -l /sys/bus/w1/devices/
total 0
lrwxrwxrwx 1 root root 0 Oct 29 14:20 10-0008028a88e3 -> ../../../devices/w1_bus_master1/10-0008028a88e3
lrwxrwxrwx 1 root root 0 Nov 2 14:09 w1_bus_master1 -> ../../../devices/w1_bus_master1

That worked, the sensor was detected and identified as 10-0008028a88e3. Let’s poke it with a stick and see what happens:

cat /sys/bus/w1/devices/10-0008028a88e3/w1_slave
22 00 4b 46 ff ff 0d 10 fb : crc=fb YES
22 00 4b 46 ff ff 0d 10 fb t=16937

The above output is rather difficult to read but it does show the temperature! I have written some quick and dirty shell code to make it easier to read. At the same time the temperature reading will be exported to to visualise it in a nice graph!

beertemp=`cat /sys/bus/w1/devices/10-0008028a878b/w1_slave | awk 'NR==2' | awk '{print $10}' | cut -c1-6 | sed 's/^..//' | awk '{ foo = $1 / 100 ; print foo }'`

cosm=`curl -s –request PUT –header “X-ApiKey: xxxxxxxxxxxxxxxxxxxxxxxxxxxx” –data “BeerTemp1, $beertemp”`

if [ “$beertemp” != “-1.25” ];




And there it is!

Tweeting beer temperature sensor

Unfortunately, once in a while the sensor encounters a CRC error and outputs a temperature reading of -1.25C.

ff ff ff ff ff ff ff ff ff : crc=c9 NO
22 00 4b 46 ff ff 0f 10 6a t=-1250

Probably something to do with my bad wiring! I had to correct it in the above code, asking it to do nothing if crc error was encountered. It should make sense for now and I don’t expect temperature dropping indoors to -1.25C any time soon!

Now let’s make the script tweet if the temperature is below 21C, the ideal fermentation conditions for my stout. If I know that the temperature is too low, I can adjust the thermostat on the fish tank heater.

I used TTYtter, a Perl script which makes command line tweeting a breeze. Here’s the tweeting beer temperature sensor code:


beertemp=`curl -s –request GET –header “X-ApiKey: XXXxxxxxxxxxxxxxxXXXXXX” | grep -i beer | awk -F “\”*,\”*” ‘{print $3}’| awk ‘{printf “%.0f\n”, $1}’`


tweet=`echo @am3rig0 Beer is too cold. Right now it is at $beertemp C. Sort it out mate! It is lower than $beermintemp C.`

if [ $beertemp -lt $beermintemp ];


/home/amerigo/ -status=”$tweet”


The shell scripts were added to crontab and are executed frequently. This should make my life much easier, I won’t have to look at the graphs all the time and if temperature is too low I will get a tweet informing me of this!

Tweeting beer temperature sensor

It looks like the ttytter script is checking for duplication when sending the tweets. This stopped my script from working properly as it was sending the same message whenever the temperature dropped below required level.

To fix this, I created a list of different messages stored in twitdb.txt, which ttytter was randomly using when sending a tweet. Here’s the code:

beertemp=`curl -s --request GET --header "X-ApiKey: XXXxxxxxxxxxxxxxxXXXXXX" | grep -i beer | awk -F "\"*,\"*" '{print $3}' | awk '{printf "%.0f\n", $1}'`


tweet=`awk ‘BEGIN{srand(‘$RANDOM’)} {if(rand()*NR<1)s=$0} END{print s} ‘ twitdb.txt`

if [ $beertemp -lt $beermintemp ];
/home/amerigo/ -status=”$tweet ($beertemp.C)”