Monday, January 14, 2013

Pushing Raspberry Pi Data to Pachube using bash and cron

The Pachube API makes it very easy for you to make your Raspberry Pi part of the Internet of Things (IoT). After successfully following this short tutorial, you or any computer connected to the Internet will be able to keep track of how your Raspberry Pi is doing. Even more useful if you have more than one and wish to track them all at once.
This blog post is the result of a brief tutorial I made in Google+'s Raspberry Pi community for +Kim Huebel.


Raspberry Pi
  1. Raspberry Pi connected to the Internet.
  2. Debian-flavor "ifstat command". Run "ifstat -v"; You should have version 1.1.
  3. realpath command for Run "realpath --version" to see if you have it installed. Use apt-get or pacman to install it depending on which linux distro you are using.
Arch Linux users: You WILL have to download the source code for ifstat and compile it yourself if you want to monitor a network interface with this script. Arch Linux's ifstat command output format is significantly different from Debian's ifstat. You will otherwise have to modify rpi2pachube to work with whatever flavor of ifstat Arch Linux uses if you do not wish to do this.

Create a feed on Pachube

  1. Create an account on Pachube if you don't have one already and log in with your account.
  2. Add a new device/feed by clicking on the +Device/Feed button.
    1. Select "Something else" when prompted for device type.
    2. Select "No, I will push data to Cosm" when asked for an existing data source.
    3. Give your device/feed a title. (e.g. raspberry-pi-1)
    4. Optional: Add tags to your new device. (e.g., raspberry pi, network, performance)
    5. Click Create.
    6. Write down the feed ID, as you will need this later for configuring the script.
  3. Click "Keys" in your console and then click the +Key button to add a new key.
    1. Label your key. (e.g. raspberry-pi-update)
    2. Set feed restriction to "Use specific feed(s)" and select the Device/feed you created earlier.
    3. Only "update" is needed in Access Privileges.
    4. Click Create.

Download rpi2pachube from Github

  1. Make a directory where you want rpi2pachube folder to be located. (e.g. ~/scripts).
    • mkdir -p ~/scripts
  2. CD into that directory: (e.g. cd ~/scripts/)
    • cd ~/scripts
  3. Clone the git repository.
    • git clone
  4. Run the configuration utility.
    • cd rpi2pachube
    • ./
  5. When prompted, answer with your Pachube API Key, Feed ID and a Network Interface to monitor.
The configuration utility creates the file ~/.rpi2pachube.conf where your configuration is stored.
It is also possible to manually create a global configuration file in /etc/rpi2pachube.conf but that is unnecessary and not recommended.
Run the configuration utility ( instead of manually editing ~/.rpi2pachube.conf.
Your Raspberry Pi performance values will be pushed to Pachube every 5 minutes. To change it, edit your user's crontab file (e.g. crontab -e).

That is all! Feel free to leave a comment.

Official Google+ Post in the Raspberry Pi community.

Update (Wed, Jan 23rd, 2013): Added "realpath" as a requirement. Renamed script to rpi2pachube and moved repository to a new location.

Legal disclaimer: All mentions of the letter sequence "cosm" on this post or Github repository (or in combination with other letters, or any other representation) refer ONLY to the on-line database service called Pachube and NOT to Cosm®, a trademark that is registered to Mithral Inc.


  1. Thanks for posting this project. Being new to linux I have learned quite a bit looking at your code.
    I have been able log data to COSM when executing from the command line. However when it runs from cron I get this -

    Jan 22 21:42:01 raspberrypi /USR/SBIN/CRON[6157]: (pi) CMD (/scripts/rpi2cosm/
    Jan 22 21:42:01 raspberrypi /USR/SBIN/CRON[6156]: (CRON) info (No MTA installed, discarding output)

    From what I can find out the output of cron results in an email, which is not installed. Is this what I should expect?

    1. Todd,

      Partly, cron trying to send you an e-mail but it is failing because there's no application installed to send you an e-mail. The other part (and the main one) is that maybe your path is wrong. Did you run the
      Can you make sure that is located in /scripts/rpi2cosm/ ? Or did you place it in your user directory?

    2. Thanks for the quick reply! I had problems at first with the "realpath" variable in I entered the cron information using crontab but failed to add ~ in front of the path. Now it works as planned. Thanks for making me take one more look!

    3. I've relocated the repository and updated the setup script to require 'realpath' to be installed. I believe that is why realpath was giving you trouble. Running sudo apt-get install realpath on a Debian distro should fix it.

  2. Hi,
    i like your solution but when try to clone receive this error:

    git clone
    Cloning into 'rpi2pachube'...
    Permission denied (publickey).
    fatal: The remote end hung up unexpectedly

    can you help me ?


  3. I looked online for how to solve that and everything points to this:

    So, follow the steps on that page.

  4. This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. virtual pbx system