0
0
Raspberry Piprogramming~30 mins

InfluxDB for time-series data in Raspberry Pi - Mini Project: Build & Apply

Choose your learning style9 modes available
InfluxDB for Time-Series Data on Raspberry Pi
📖 Scenario: You have a Raspberry Pi collecting temperature data every minute. You want to store this data in InfluxDB, a database designed for time-series data. This project will guide you to create a simple Python script that writes temperature readings to InfluxDB and then queries the stored data.
🎯 Goal: Build a Python script that connects to InfluxDB, writes temperature data points, and retrieves the stored data to display it.
📋 What You'll Learn
Use the influxdb-client Python library to connect to InfluxDB
Create a data point with measurement, tags, fields, and timestamp
Write data points to InfluxDB
Query data points from InfluxDB
Print the queried data
💡 Why This Matters
🌍 Real World
Storing and analyzing sensor data like temperature, humidity, or CPU usage over time on a Raspberry Pi.
💼 Career
Skills in time-series databases and IoT data handling are valuable for roles in data engineering, IoT development, and system monitoring.
Progress0 / 4 steps
1
Setup InfluxDB Client Connection
Import InfluxDBClient from influxdb_client and create a client instance called client connecting to "http://localhost:8086" with token "my-token" and org "my-org".
Raspberry Pi
Need a hint?

Use InfluxDBClient constructor with url, token, and org parameters.

2
Create Write API and Prepare Data Point
Create a write API instance called write_api from client.write_api(). Then create a data point string called point with measurement "temperature", tag location="office", field value=23.5, and current timestamp using InfluxDB line protocol format.
Raspberry Pi
Need a hint?

Use client.write_api() to get the write API. The data point string uses the format: measurement,tag=value field=value.

3
Write Data Point to InfluxDB
Use write_api.write() to write the point to bucket "my-bucket" and org "my-org".
Raspberry Pi
Need a hint?

Call write_api.write() with bucket, org, and record parameters.

4
Query and Print Stored Temperature Data
Create a query API instance called query_api from client.query_api(). Write a Flux query string query to select all temperature values from bucket "my-bucket" in the last 1 hour. Use query_api.query() to run the query and print each record's _time and _value.
Raspberry Pi
Need a hint?

Use client.query_api() to get the query API. Write a Flux query string to select data from the last hour. Loop through results and print time and value.