Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lpla/7e492ab8a02a81eb3422906cc6ccc2c8 to your computer and use it in GitHub Desktop.
Save lpla/7e492ab8a02a81eb3422906cc6ccc2c8 to your computer and use it in GitHub Desktop.
Install MQTT + influxDB + telegraf + grafana in Raspberry Pi 1 or Zero (armv6)

I tried to install this set of technologies for an small home project using BME280 in a Raspberry Pi Zero, but all guides I tried to follow are based on newer Raspberry Pi versions (armv7) (like this guide or this one), so the docker instructions don't work for some of these packages.

TL;DR: don't use any docker image, use only apt commands and repos from each project official documentation

Mosquitto (MQTT)

As official documentation details, simply use the already available package from Raspbian/Raspberry Pi OS archive repository:

sudo apt install mosquitto

Once installed, it should be then automatically running and configured through systemctl to run on boot.

InfluxDB and telegraf

Again, let's follow the official documentation for telegraf (the same page for influxDB doesn't work well for raspbian because the command expects DISTRIB_ID=$(lsb_release -si) to be 'debian' or 'ubuntu', not 'raspbian'). More specifically, let's use the Debian command specified there:

# Before adding Influx repository, run this so that apt will be able to read the repository.

sudo apt-get update && sudo apt-get install apt-transport-https

# Add the InfluxData key

wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -  
source /etc/os-release  
test $VERSION_ID = "7" && echo "deb https://repos.influxdata.com/debian wheezy stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
test $VERSION_ID = "8" && echo "deb https://repos.influxdata.com/debian jessie stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
test $VERSION_ID = "9" && echo "deb https://repos.influxdata.com/debian stretch stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
test $VERSION_ID = "10" && echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list

Then, once the repository and keys are installed in apt, then let's install both packages and set them up on boot:

sudo apt-get update && sudo apt-get install influxdb telegraf
sudo systemctl start telegraf
sudo systemctl unmask influxdb.service
sudo systemctl start influxdb

In my case, I needed to create a database and a user in the influxDB, so let's run:

influx

And then, in the influx terminal:

create database sensors

create user telegraf with password "telegraf"

grant all on sensors to telegraf

We are done with influxDB. Before using Telegraf, it is necessary to configure it. The first thing is creating a default configuration that we will modify to adapt it to our scenario:

telegraf config > telegraf.conf

Now, it is possible to configure Telegraf. Open telegraf.conf and look for inputs.mqtt_consumer and uncomment these lines:

servers = ["tcp://localhost:1883"]
topics = [
  "sensors"
]
data_format = "influx"

Then, we need to modify the output section. Look for outputs.influxdb and modify the following lines:

urls = ["http://127.0.0.1:8086"]
database = "sensors"
skip_database_creation = true
username = "telegraf"
password = "telegraf"

Now, we can run Telegraf with the new config:

sudo mv telegraf.conf /etc/telegraf/telegraf.conf
sudo systemctl restart telegraf
sudo systemctl status telegraf

Grafana

Let's run the official documentation installation instructions, as grafana is compiled for armv6:

wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list

sudo apt-get update && sudo apt-get install grafana

Now let's start the service and enable it on boot as documentation says:

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

sudo systemctl enable grafana-server.service

And that's all! Grafana should now be configurable with the InfluxDB, and show data from the database written by projects like the ones mentioned in the several tutorials regarding BME280 and MQTT clients you can find in Google. Like MQTT clients for ESP32 or Raspberries written in Golang, Javafx or Python (https://github.com/Scott8586/bme280-python-mqtt).

@lpla
Copy link
Author

lpla commented Sep 7, 2021

Also, if Node.js >= 12 is needed, follow this guide, as armv6l architecture is no longer officially supported by Node.js devs, but still built in their Node.js Unofficial Builds site: https://hassancorrigan.com/blog/install-nodejs-on-a-raspberry-pi-zero/

@freakyuser-osm
Copy link

freakyuser-osm commented Mar 31, 2023

Thanks for the guide!
Note: The influxdb repo needs meanwhile the following key:
curl -sL https://repos.influxdata.com/influxdata-archive.key | sudo apt-key add -

For some reason I had to install grafana with wget & dpkg. My assumption is, that apt-get fetches the armv7 build, but who knows :D
Select armv6 from:
https://grafana.com/grafana/download?edition=oss&pg=get&platform=arm&plcmt=selfmanaged-box1-cta1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment