The easiest way to visualize your IoT data with Grafana and Raspberry Pi

Learn how to install Grafana, an open-source data visualization tool, on a Raspberry Pi and use it to monitor your IoT projects. …


Updated August 13, 2023

Need help with your Raspberry Pi?
Contact Me!

Do you love silly Raspberry Pi Projects?
Check out my this YouTube Channel!


Learn how to install Grafana, an open-source data visualization tool, on a Raspberry Pi and use it to monitor your IoT projects.

Grafana is an open-source data visualization tool that allows users to create beautiful dashboards to display real-time metrics and data from various sources. It supports many data sources including Prometheus, InfluxDB, MySQL, and Graphite just to name a few. In this article, we will show you how to install Grafana on a Raspberry Pi and configure it to work with InfluxDB - a popular time-series database used for storing IoT sensor data.

Prerequisites

Before proceeding with the installation, make sure your Raspberry Pi is running Raspbian or any other compatible operating system. We will use Raspbian in this tutorial. You should also have InfluxDB installed and configured on your Raspberry Pi. If you haven’t done that yet, follow this guide to get started with InfluxDB.

Installing Grafana

To install Grafana on Raspberry Pi, we will use the official Grafana ARM binary package. Run the following commands in your terminal:

wget https://dl.grafana.com/oss/release/grafana_7.2.0_armhf.deb
sudo dpkg -i grafana_7.2.0_armhf.deb

After downloading and installing the package, start Grafana using:

sudo systemctl daemon-reload
sudo systemctl enable grafana-server
sudo systemctl start grafana-server

Configure InfluxDB as a Data Source

Now that Grafana is installed, we need to add InfluxDB as a data source. Open your web browser and navigate to http://<your_raspberry_pi_ip>:30000, where <your_raspberry_pi_ip> is the IP address of your Raspberry Pi. You should see Grafana’s login page. Use the default credentials (admin for both username and password) to log in for the first time.

Once logged in, click on Configuration (gear icon) in the sidebar and select Data Sources. Click on Add Data Source. In the form that appears, select InfluxDB as the data source type.

Fill out the following fields:

  • Name: A name for your InfluxDB data source (e.g., “IoT Data”)
  • URL: The IP address and port of your InfluxDB instance (e.g., http://<your_raspberry_pi_ip>:8086)
  • Database: The name of the database you want to use (e.g., “iot_data”)
  • Username: The username used to access InfluxDB (default is usually “admin”)
  • Password: The password for your InfluxDB user

Click on Save & Test to ensure that Grafana can connect to your InfluxDB instance. If everything is configured correctly, you should see a success message.

Create a Dashboard and Visualize Data

Now that we have connected Grafana to InfluxDB, let’s create a simple dashboard to visualize our IoT data. Click on the + icon in the sidebar and select Dashboard. Then click on Add new panel.

In the panel editor, choose a visualization type (e.g., Graph). In the Query tab, select your InfluxDB data source from the dropdown menu. Write a query to retrieve data from your IoT sensors. For example:

SELECT "temperature" FROM "iot_data"."autogen"."sensor_readings" WHERE $timeFilter GROUP BY time($__interval) fill(null)

This query retrieves the temperature values from the sensor_readings measurement in the iot_data database. $timeFilter is a Grafana variable that allows you to select a time range for your data. $__interval is another Grafana variable that adjusts the data resolution based on the current dashboard time window size.

In the Axes & Grid tab, customize the axes and grid settings as desired. Then click on Apply. You should see a graph of your IoT sensor data displayed on the dashboard.

You can add more panels to display different metrics or use other types of visualizations like Gauges, Stat, Table, etc. Experiment with Grafana’s features and create a customized dashboard for your specific needs.

To save the dashboard, click on the Save Dashboard icon in the top right corner and give it a name. Now you can share this dashboard with others or access it later by clicking on the Dashboards link in the sidebar.

Congratulations! You have successfully installed Grafana on your Raspberry Pi and configured it to work with InfluxDB. Start collecting IoT data from your sensors and visualize them in real-time using Grafana’s powerful features.