Technical Blog

The Tweeting Kegerator, Built with the BeagleBone Black

For this project we connected our beloved Kegerator to the Internet, making it a tweeting kegerator. We attached a flowmeter on the Kegerator, connected this sensor to the BeagleBone, which calculates the number of beers served and then posts this information to its own Twitter account. Read the following articles to setup the board and learn a little bit about MQTT protocol. We will also walk you through the set-up process.

The Hardware

For this project we used the Swissflow 800 flowmeter, placing it between the keg and the tap following the sensor’s manual. We also had to find a way to extend the flowmeter’s wires out of the fridge. There are three: +5V, GND, and the flow measure.


Plug the 5V wire to the Beaglebone P9_07 pin and the GND wire to the P9_01 pin. You can use any GPIO pin to connect the last wire but in our example it will be the P8_13 pin.

Installing the Twitter library for Python

We used the Twython library but there are many more. You may find the official documentation here. We found difficulties installing this library using pip or easy_install; there seems to be a bug with our version of angstrom (the BeagleBone OS). However, you can skirt this issue if you install pip version 1.2.1. After that, run: pip install twython.

Create a Twitter account for your Kegerator

You can create a new account or use an existing one but you will have to register the BeagleBone to this account.

  1. Go to here and log in if necessary in order to create a new application (which will be your program on the BeagleBone).
  2. Supply the necessary required fields.
  3. Submit the form.
  4. Copy the consumer key (API key) and consumer secret from the screen into your application.
  5. Configure the application permission level as read-write.
  6. On the application’s detail page, invoke the “Your access token” feature to automatically negotiate the access token at the permission level you need.
  7. Copy the indicated access token and access token secret from the screen into your application

The code

Fill the four Twitter fields with the credentials you created in the previous step and run your program. You can put a debug print in the main loop to check how many ticks you catch with the GPIO interrupt.

import Adafruit_BBIO.GPIO as GPIO
import os
import glob
import time
from twython import Twython

tick_count = 0
beers = 0
COUNTS_PER_BEER = 1400 # 1 litter = 5600 ticks so 1 glass = 1/4 litter = 250ml = 5600 ticks / 4 = 1400 ticks
APIKey = ""
APISecret = ""
TOKENKey = ""
TOKENSecret = ""

def flow(event):
    global tick_count
    tick_count += 1

def setup():
    GPIO.setup("P8_13", GPIO.IN)
    GPIO.add_event_detect("P8_13", GPIO.FALLING, flow)

def close():
    print "Disconnect"

    twitter = Twython(APIKey, APISecret, TOKENKey, TOKENSecret)

    while True:
        if (tick_count / COUNTS_PER_BEER) != beers:
            print "beers: ", tick_count / COUNTS_PER_BEER
            beers = tick_count / COUNTS_PER_BEER
            str = "beers served: " + str(beers)

except (KeyboardInterrupt):
    print "Interrupt received"


Now for some tests. If it’s not working, check your error messages. We found the following problems during our tests:

  • Double check your Twitter credentials.
  • The ssl package for python was not installed or outdated:

pip install ssl

  • The python package was outdated:

opkg upgrade python

  • The date on the BeagleBone was not the same as the date on Twitter’s servers API:

ntpdate -b -s -u

Time for some beer! Pour yourself a pint and check the Twitter account. Your status should be updated!