Skip to content

Instantly share code, notes, and snippets.

@lpla
Last active December 30, 2024 09:33
Show Gist options
  • 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 as they don't exist for armv6, 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 or for influxDB. More specifically, let's use the Debian command:

curl --silent --location -O \
https://repos.influxdata.com/influxdata-archive.key \
&& echo "943666881a1b8d9b849b74caebf02d3465d6beb716510d86a39f6c8e8dac7515  influxdata-archive.key" \
| sha256sum -c - && cat influxdata-archive.key \
| gpg --dearmor \
| sudo tee /etc/apt/trusted.gpg.d/influxdata-archive.gpg > /dev/null \
&& echo 'deb [signed-by=/etc/apt/trusted.gpg.d/influxdata-archive.gpg] https://repos.influxdata.com/debian stable main' \
| sudo tee /etc/apt/sources.list.d/influxdata.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 update && sudo apt 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 and starting instructions, as grafana is compiled for armv6:

sudo apt-get install -y apt-transport-https software-properties-common wget
sudo mkdir -p /etc/apt/keyrings/
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
# Updates the list of available packages
sudo apt-get update
# Installs the latest OSS release:
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 Dec 30, 2024

For completeness sake, here I leave my fork of the bme280-python-mqtt repo with some changes for my personal setup (including Celsius temp instead of Fahrenheit):

https://github.com/lpla/bme280-python-mqtt

And a small daemon to show the local BME280 sensor data in a SSD1306 screen:

https://github.com/lpla/pi_thermo_hygrometer

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