Visit our new documentation site! This documentation page is no longer updated.

Sensor Data Analytics with Raspberry Pi

Raspberry Pi is a credit-card-sized single-board computer. Because it is low-cost and easy to equip with various types of sensors, using Raspberry Pi as a cloud data logger is one of its ideal use cases.

This article introduces how to transport sensor data from Raspberry Pi to Treasure Data.

Table of Contents

Install Raspbian

Raspbian is a free operating system based on Debian, optimized for the Raspberry Pi. Please install Raspbian on your Raspberry Pi by following the instructions in the blog post below:

Install Treasure Agent (Fluentd)

Next, we’ll install Treasure Agent (Fluentd) on Raspbian. Raspbian bundles Ruby 1.9.3 by default, but we need the extra development packages.

$ sudo aptitude install ruby-dev

We’ll now install Treasure Agent (Fluentd) and the necessary plugins.

$ sudo gem install fluentd
$ sudo fluent-gem install fluent-plugin-td

Configure and Launch Treasure Agent

Sign into your Treasure Data account. You can get your account’s API key from the users page. If you don’t have an account, please schedule a free trial to get started.

Please prepare the fluent.conf file with the following information, including your API key.

<match td.*.*>
  type tdlog

  buffer_type file
  buffer_path /home/pi/td
  type http
  port 8888
  type forward

Finally, please launch Treasure Agent (Fluentd) via your terminal.

$ fluentd -c fluent.conf

Upload Test

To test the configuration, just post a JSON message to Treasure Agent via HTTP.

$ curl -X POST -d 'json={"sensor1":3123.13,"sensor2":321.3}' \
If you're using Python, you can use python logger library.

Now, access the databases page to confirm that your data has been uploaded to the cloud properly.

You can now issue queries against the imported data.

For example, these queries calculate the average sensor1 value and the sum of sensor2 values.

SELECT AVG(sensor1) FROM raspberrypi;
SELECT SUM(sensor2) FROM raspberrypi;


Raspberry Pi is an ideal platform for prototyping data logger hardware. By combining Raspebrry Pi and Treasure Data, we can easily analyze the physical world in the cloud.

Last modified: Oct 09 2017 18:19:48 UTC

If this article is incorrect or outdated, or omits critical information, let us know. For all other issues, access our support channels.