Basics
Tutorials
Projects
Interfaces
Integrations
Hardware
Firmware
tools
Documentation

Grafana for Visualization

Grafana is an open platform for beautiful analytics and monitoring. It allows you to create a nice looking dashboards that will give you quick insights into your sensor data.

Requirements

You will need these components to make it work:

  • Debian-based Linux, or macOS

  • Mosquitto - MQTT broker

This setup has been tested on:

  • Raspberry Pi 3 + Raspbian Jessie

  • Turris Omnia + Ubuntu 16.04 (via LXC container)

  • macOS 10.13

Installing InfluxDB on Linux

Step 1: Install dependency packages

sudo apt install apt-transport-https curl -y

Step 2: Add repository key

curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -

Step 3: Add repository to source list

Debian / Raspbian
Ubuntu
echo "deb https://repos.influxdata.com/debian stretch stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
echo "deb https://repos.influxdata.com/ubuntu/ xenial stable" | sudo tee /etc/apt/sources.list.d/influxdb.list

Step 4: Update the package list and install the packages

sudo apt update && sudo apt install influxdb

Step 5: Now you can start the InfluxDB service

sudo systemctl start influxdb

Installing Grafana on Linux

Step 1: Install dependencies

sudo apt install adduser libfontconfig -y

Step 2: Based on your taget platform, select the appropriate procedure

Raspberry Pi and Omnia LXC
Desktop (Ubuntu and Debian

Step 1: You can manualy download latest version from Grafana, or you can use the following helper to download it for you

wget $(wget "https://api.github.com/repos/fg2it/grafana-on-raspberry/releases/latest" -q -O - | grep browser_download_url | grep armhf.deb | head -n 1 | cut -d '"' -f 4) -O grafana.deb

Step 2: Then install the package

sudo dpkg -i grafana.deb

Step 1: Add repository key

curl -sL https://packages.grafana.com/gpg.key | sudo apt-key add -

Step 2: Add repository to source list

echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list

Step 3: Then update the package list and install the package

sudo apt update && sudo apt install grafana -y

Step 3: Reload the systemd configuration

sudo systemctl daemon-reload

Step 4: Enable Grafana on boot

sudo systemctl enable grafana-server

Step 5: Now you can start the Grafana server

sudo systemctl start grafana-server

Continue in the section Connect Mosquitto and InfluxDB.

Installing InfluxDB on macOS

Step 1: Open the Terminal application.

Step 2: Make sure you have Homebrew installed.

Step 3: Install InfluxDB

brew install influxdb

Step 4: Enable InfluxDB service

brew services start influxdb

Installing Grafana on macOS

Step 1: Open the Terminal application

Step 2: Make sure you have Homebrew installed

Step 3: Install Grafana

brew install grafana

Step 4: Enable Grafana service

brew services start grafana

Connect Mosquitto and InfluxDB

Step 1: Install the MQTT to InfluxDB service

sudo pip3 install --upgrade mqtt2influxdb

Step 2: Create the /etc/bigclown directory

sudo mkdir /etc/bigclown

Step 3: Open the configuration file

For text editing, we use nano editor. You can save changes by pressing key combination Ctrl + O and exit editor by pressing Ctrl + X.

sudo nano /etc/bigclown/mqtt2influxdb.yml

Step 4: Paste this snippet to the configuration file

/etc/bigclown/mqtt2influxdb.yml
mqtt:
host: 127.0.0.1
port: 1883
influxdb:
host: 127.0.0.1
port: 8086
database: node
points:
- measurement: temperature
topic: node/+/thermometer/+/temperature
fields:
value: $.payload
tags:
id: $.topic[1]
channel: $.topic[3]
- measurement: relative-humidity
topic: node/+/hygrometer/0:4/relative-humidity
fields:
value: $.payload
tags:
id: $.topic[1]
- measurement: illuminance
topic: node/+/lux-meter/0:0/illuminance
fields:
value: $.payload
tags:
id: $.topic[1]
- measurement: pressure
topic: node/+/barometer/0:0/pressure
fields:
value: $.payload
tags:
id: $.topic[1]
- measurement: co2
topic: node/+/co2-meter/-/concentration
fields:
value: $.payload
tags:
id: $.topic[1]
- measurement: voltage
topic: node/+/battery/+/voltage
fields:
value: $.payload
tags:
id: $.topic[1]
- measurement: button
topic: node/+/push-button/+/event-count
fields:
value: $.payload
tags:
id: $.topic[1]
channel: $.topic[3]

In the section tags you can your identifiers, e.g.: tags: room: bedroom

Step 5: Configuration file test

mqtt2influxdb -c /etc/bigclown/mqtt2influxdb.yml --test

Step 6: Start the MQTT to InfluxDB service

pm2 start `which python3` --name "mqtt2influxdb" -- `which mqtt2influxdb` -c /etc/bigclown/mqtt2influxdb.yml

Step 7: Save the PM2 state (so it will start after reboot)

pm2 save

If you want to see temperature records from database in CSV format, use this command:

influx -database node -execute "select * from temperature;" -format csv

Then you must restart the service when you change the configuration file

pm2 restart mqtt2influxdb

Configure Grafana

Step 1: Open the Grafana web interface at http://localhost:3000/ or http://hub.local:3000/ or http://ip:3000/ and log in

  • Enter the User admin

  • Enter the Password admin

Step 2: Create a data source

Select Add data source and then:

  • Enter the Name: node

  • Select the Type: InfluxDB

  • Enter the URL: http://localhost:8086

  • Enter the Database: node

Finish by clicking on the Add button. At this moment Grafana will try to connect to the data source and replies back with the message Data source is working.

Step 3: Download dashboard.json or copy the content of this file to clipboard

Step 4: Import the visualization dashboards, click the Grafana icon (top left button), select Dashboards in the menu, then choose Import

Step 5: Upload the dashboard.json file or paste the JSON from clipboard

Step 6: Choose node as a data source and click on Import

Related Documents

Contents
Requirements
Installing InfluxDB on Linux
Step 1: Install dependency packages
Step 2: Add repository key
Step 3: Add repository to source list
Step 4: Update the package list and install the packages
Step 5: Now you can start the InfluxDB service
Installing Grafana on Linux
Step 1: Install dependencies
Step 2: Based on your taget platform, select the appropriate procedure
Step 3: Reload the systemd configuration
Step 4: Enable Grafana on boot
Step 5: Now you can start the Grafana server
Installing InfluxDB on macOS
Step 1: Open the Terminal application.
Step 2: Make sure you have Homebrew installed.
Step 3: Install InfluxDB
Step 4: Enable InfluxDB service
Installing Grafana on macOS
Step 1: Open the Terminal application
Step 2: Make sure you have Homebrew installed
Step 3: Install Grafana
Step 4: Enable Grafana service
Connect Mosquitto and InfluxDB
Step 1: Install the MQTT to InfluxDB service
Step 2: Create the /etc/bigclown directory
Step 3: Open the configuration file
Step 4: Paste this snippet to the configuration file
Step 5: Configuration file test
Step 6: Start the MQTT to InfluxDB service
Step 7: Save the PM2 state (so it will start after reboot)
Configure Grafana
Step 1: Open the Grafana web interface at http://localhost:3000/ or http://hub.local:3000/ or http://ip:3000/ and log in
Step 2: Create a data source
Step 3: Download dashboard.json or copy the content of this file to clipboard
Step 4: Import the visualization dashboards, click the Grafana icon (top left button), select Dashboards in the menu, then choose Import
Step 5: Upload the dashboard.json file or paste the JSON from clipboard
Step 6: Choose node as a data source and click on Import
Step 7: Result for Wireless Climate Monitor and Wireless CO2 Monitor
Related Documents