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
  apikey YOUR_API_KEY_HERE

  auto_create_table
  buffer_type file
  buffer_path /home/pi/td
</match>
<source>
  type http
  port 8888
</source>
<source>
  type forward
</source>

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}' \
  http://localhost:8888/td.testdb.raspberrypi
Untitled-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;

Conclusion

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


Last modified: Dec 24 2016 00:46:56 UTC

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