Setting up InfluxDB and Grafana for storing and viewing Arduino measured sensor values

Intro

Arduino and its related products are undoubtedly very popular among hobbyists and even professionals. One of the areas of interest with hobbyists and professionals is interfacing with many different sensors such as temperature, humidity, light, etc. The simplest method would be storing measured values on an SD card or transmitting the data over the serial interface, but there are times where a prolonged measurement session is a requirement. In this case, storing data in a database over Serial, Ethernet or WiFi is the best solution. In this article I will talk about setting up InfluxDB on a Linux platform and how to store data in it, and how to view measurement data using Grafana.

What is InfluxDB?

InfluxDB is an open-source time series database developed by InfluxData. It is written in Go and optimized for fast, high-availability storage and retrieval of time series data in fields such as operations monitoring, application metrics, Internet of Things sensor data, and real-time analytics.

InfluxDB has no external dependencies[and provides an SQL-like language with built-in time-centric functions for querying a data structure composed of measurements, series, and points. Each point consists of several key-value pairs called the fieldset and a timestamp. When grouped together by a set of key-value pairs called the tagset, these define a series. Finally, series are grouped together by a string identifier to form a measurement. Some of the InfluxDB’s features are:

  • Values can be 64-bit integers, 64-bit floating points, strings, and booleans.
  • Points are indexed by their time and tagset.
  • Retention policies are defined on a measurement and control how data is downsampled and deleted.
  • Continuous Queries run periodically, storing results in a target measurement.
  • Line Protocol: Store data through HTTP, TCP or UDP protocols.

A very good point about InfluxDB for use with microcontrollers is that it does not necessarily require any timestamp as it automatically adds the time of arrival of the data (server time).

Installing InfluxDB on Linux

You should head on to InfluxDB’s download page in order to get the latest release version of InfluxDB. At the time of writing this article, the version is 1.1.1. In the download page, you will be given the chance to download the appropriate version for your Linux distribution. But  to make the stuff going faster here is the commands you need to execute to install InfluxDB (version 1.1.1):

If you are on Ubuntu or other Debian-based flavors:

If you are on RedHat or CentOS:

You can also install InfluxDB on Windows, but since this guide is focused on Linux, you will be on your own for that matter (it is really simple, don’t worry!)

Setting up InfluxDB on Linux

After installation, to generate the configuration file, run the following command (note that the command is influxd that is without the at the end!):

After running this command, there will be a config file in the ‘/etc/influxdb‘ named ‘influxdb.conf’. To change the default configuration you need to edit this file. I should remind you that this folder is write protected so you will need root access to be able to edit this file.

The most important options to check or change are listed below (you can read the exact purpose from the comments written in the config file by the developers) Make sure you uncomment the section directive as well if you are going to change it, e.g., uncomment the [admin] by removing the hash character!:

  1. In the [admin] section make sure the admin page is enabled by removing the comment character ‘#‘ and setting it to ‘enabled = true
  2. Since we are going to use the HTTP protocol to write values into InfluxDB, make sure it is also enabled under the [http] section of the config file.
  3. If necessary, you can change the default port numbers for Administrator Panel (8083) and HTTP (8086).

Now in the terminal, running the command below starts the InfluxDB as a service (change start to stop to end the service!):

Alternatively, if you want to see the output messages of InfluxDB live, you can start it in standalone mode (not as a service) by the following command:

That command starts the InfluxDB and tells it to use the configuration file that we just edited.

Now, if you open your browser and go to ‘http://localhost:8083‘ (or the another port if you have changed it in the config file), you will be greeted by the administration panel of InfluxDB.

InfluxDB folders

By default, the following folders will be created (again, read the config file’s comments for exact details) :

  • /home/[username]/.influxdb => contains user specific data and meta folders to store databases.
  • /var/log/influxdb => this folder will contain logs such as warnings and errors
  • /var/lib/influxdb => this folder contains the variable state information, database engine, etc.
  • /etc/influxdb => this folder contains configuration file(s)

The whole process in a GIF animation

Install setup and start influxdb on ubuntu

At the moment, there is not an awful lot of data to see there 😉 so in the next steps we will discuss the line protocol which is the way of sending data to InfluxDB, and then we send some data from Arduino over Ethernet to InfluxDB!

Saeid Yazdani

An Electronics Engineer with passion in Embedded Systems, Wireless Sensor Networks, Assembly, Desktop and Mobile Development, Web Development and generally anything that has to do with hardware and software of any kind!

Leave a Reply

Your email address will not be published. Required fields are marked *