# Raspberry Pi Import Integration [Raspberry Pi](http://www.raspberrypi.org/) 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. You can import sensor data from Raspberry Pi into Treasure Data. # Install Raspbian [Raspbian](http://www.raspbian.org/) is a free operating system based on Debian, optimized for the Raspberry Pi. Install Raspbian on your Raspberry Pi by following the instructions in the blog post below: - [Getting Started with Raspberry Pi: Installing Raspbian](http://www.andrewmunsell.com/blog/getting-started-raspberry-pi-install-raspbian) # 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 Or, you can use fluent-bit instead of fluentd. See the detail in the following doc. http://fluentbit.io/documentation/0.12/installation/raspberry_pi.html ``` # Configure and Launch Treasure Agent [Sign into your Treasure Data account](https://console.treasuredata.com/users/sign_in). You can get your account’s API key from the [users page](https://console.treasuredata.com/users/current). If you don’t have an account, [schedule a free trial](https://www.treasuredata.com/request_trial/) to get started. Prepare the fluent.conf file with the following information, including your API key. ``` type tdlog apikey YOUR_API_KEY_HERE auto_create_table buffer_type file buffer_path /home/pi/td source type http port 8888 source type forward ``` Finally, 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 ``` 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. - [Treasure Data: List of Databases](https://console.treasuredata.com/databases) You can now issue queries against the imported data. - [Treasure Data: New Query](https://console.treasuredata.com/query_forms/new) 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 Raspberry Pi and Treasure Data, we can easily analyze the physical world in the cloud.