DIY Projects

Install Grafana on macOS and Raspbian for Raspberry Pi. How to create a Dashboard for MySensors IoT with Node-RED and InfluxDB

grafana graph dashboard mysensors dht22 temperature humidite

Grafana is an Open Source software that allows time-dependent dashboards and graphs of data. Grafana runs on Windows PC (64-bit), macOS and Raspbian for Raspberry Pi. Grafana supports 6 databases (CloudWatch, Elasticsearch, Graphite, InfluxDB, OpenTSDB and Prometheus). Grafana is very well suited for displaying data from connected objects. It’s the solution of choice for creating a stylish dashboard for your Arduino, ESP8266 or ESP32 projects.

 

In this tutorial we will see how to install Grafana on Raspberry Pi or macOS. We will use the measurements of a temperature probe developed with Arduino Nano and the MySensors library. The data was collected using Node-RED and stored in an InfluxDB database.

Example, make a dashboard for your DIY connected objects

To show what can be done with Grafana, I propose to use the previous project of temperature probe developed with an Arduino Nano. The measurements are transmitted by radio waves to a Gateway MySensors. Node-RED is used to retrieve and decode the measurements transmitted using the MySensors protocol. The temperature and humidity measurements will be stored in an InfluxDB database. Finally, we will connect Grafana to the InfluxDB database to plot the graphs in real time.

Before you get started with Grafana’s installation and dashboarding, here are some articles to read to get started

Install Grafana on Raspbian for Raspberry Pi

Before installing Grafana, it is necessary to install some resources and to indicate to Raspbian or to recover the sources of Grafana

sudo apt-get install apt-transport-https curl
curl https://bintray.com/user/downloadSubjectPublicKey?username=bintray | sudo apt-key add -
echo "deb https://dl.bintray.com/fg2it/deb stretch main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install grafana

The installation lasts only a few minutes.

For security, the HTTP protocol that allows access to the WEB interface to the Grafana API is disabled. We will modify the configuration file and activate the HTTP protocol by modifying the file /etc/grafana/grafana.ini

sudo nano /etc/grafana/grafana.ini

Uncomment the http protocol and the port. For security, you can also restrict access to Grafana to specified positions with the key http_addr

[server]
# Protocol (http, https, socket)
protocol = http

# The ip address to bind to, empty will bind to all interfaces
;http_addr =

# The http port  to use
http_port = 3000

After making these changes, we restart the Grafana service

sudo service grafana-server restart

Install Grafana on macOS

macOS version tested : 10.11.6 (El Captain) on a Mac Mini 2011

Grafana installs on macOS using Brew. BREW is a package manager for Mac ( project official page).

open a Terminal and paste this command

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Answer the questions to complete the installation of Brew on your Mac.

Now we can very easily install Grafana by running this command (source of orders).

At the end of installation Brew gives us some valuable guidance on installation directories (not always well documented)

==> Downloading https://homebrew.bintray.com/bottles/grafana-3.1.1.el_capitan.bottle.1.tar.gz
######################################################################## 100,0%
==> Pouring grafana-3.1.1.el_capitan.bottle.1.tar.gz
==> Using the sandbox
==> Caveats
To have launchd start grafana now and restart at login:
  brew services start grafana
Or, if you don't want/need a background service you can just run:
  grafana-server --config=/usr/local/etc/grafana/grafana.ini --homepath /usr/local/share/grafana cfg:default.paths.logs=/usr/local/var/log/grafana cfg:default.paths.data=/usr/local/var/lib/grafana cfg:default.paths.plugins=/usr/local/var/lib/grafana/plugins
==> Summary
?  /usr/local/Cellar/grafana/3.1.1: 2,727 files, 94.0M

We start the Grafana service with this command (accept incoming connections in the window that opens after a few moments).

brew install --HEAD grafana/grafana/grafana

First connexion to Grafana

Open any internet browser and write this address

http://localhost:3000/login

Grafana has its own user management system with authentication and rights management. You can login with admin / admin.

 

Or directly create a new user account. In this case, you must fill in a name, an email and a password.

We arrive at a blank home screen

When we just create an account, the last thing left to do is the creation of an organization.

Add Data source

Before you can draw anything, it must already add data sources. Go to the menu then Data sources.

Grafana supports 6 data sources:

click Add data source to start adding a new data source.

Connect a InfluxDB database

In this tutorial, we will connect to an InfluxDB database powered by measures of a temperature (realized with the MySensors library) DHT22 probe using a Node-RED flow.

Configure data source:

In this example, I set up two data sources: Temperatures and humidity.

Add a new Dashboard

Let’s get serious now and add a new Dashboard that will contain our graphics. Open the Menu then Dashboards then + NEW.

Give it a name. Press the notched wheel then Settings (in the bar).

Give a name to the Dashboard. Here, I gave the name sensors MySensors.

Register with the small disk or CTRL+S.

Add measurements from a DHT22 MySensors probe

Open the Dashboard. The interface is a little confusing. To add a chart (or another element of the Dashboard),  you must open the small green drawer located on the left edge of the screen.

Note. There is a drawer for each line added (Add Row).

The first thing to do and choose the data source. For example select the source Temperature list Panel data source.

Then unfold the source a. selected the data to display. Here, we’ll pick Node3 (which corresponds to the node 3 of the MySensors object on which I recover measures). The Alias By field allows to assign a label that will be displayed in the legend. Otherwise, by default, Grafana uses the name of the source.

Then go to the General tab and type a title for the chart (which will be displayed at the top of the chart).

Now, in the Axes tab, you can specify the unit of measure. In this case, we will choose Celicus.

you can also set the minimum value (Y – Min) and full scale (Y – Max). It is also possible to create a second Y axis on the right. Finally, you can add lines (or areas) of threshold (Thresholds) that allows to define an area in which we would like to think the measure. Version 4 introduces a very useful alert system that we discovered in a future tutorial.

on the Legend tab, you can enable or disable its display and choose additional values: minimum, maximum, average (avg for average), current (current), total and finally the number of decimal places.

save the graph with the disc or Ctrl + S.

Discover the first graph

Once setup is complete, here is what you get. This graph shows the measures retrieved from an Arduino running MySensors. It returns the measurements of a Dallas DS18B20 waterproof probe as well as the temperature and humidity of a DHT22

You can zoom in on a portion of the chart with the mouse or using the time selector.

Open to set a custom range. We can choose to the right of the presets or manually. The key word now is used to set the current time (now). If you want action on the last hour, simply enter now-1h. Up to now (To -> Now). Finally, if we wish that the graph is updated regularly, we can choose the frequency in the Refreshing every list). Here, the graph will be updated every 5 seconds.

That’s it for the first part. Grafana is really a graphical presentation tool very powerful and fairly simple to use.

Updates

06/06/2018 – Installation procedure of Grafana on Raspbian Stretch. Links to other tutorials to develop a dashboard for IoT with Grafana

Click to rate this post!
[Total: 0 Average: 0]
Exit mobile version