Raspberry Pi Setup
Mosquitto, Node-RED, InfluxDB and Grafana
In this project, I try to work my way towards a Grafana dashboard of temperatures and humidities around the house running on a Raspberry Pi 4 and measured with ESP8266 loggers that send the measured data periodically via MQTT-protocol to the Pi. This first page deals with the Raspberry Pi installation and setup for Mosquitto, node-RED, InfluxDB and Grafana on an SSD.
Raspberry Pi 4B 4G setup
SD cards go bad eventually. I wanted to boot from an SSD via USB3 instead. The bootloader in newer Raspberry Pi 4B boards supports USB boot by default. (If necessary you can update the bootloader and select the boot order via Raspberry Pi Imager). I decided to go with a Kingston A400 240GB 2.5" SSD. At the moment, I use a DELTACO USB to SATA adapter. Find a list of working SSDs and adapters here. I installed Raspberry Pi Imager on my Windows laptop. I chose Raspberry Pi OS (other) -> Raspberry Pi OS Full (32bit) and picked the Kingston SSD as target. I then chose the options icon and filled in information for user, password, wifi, etc to use for the installation. Then I chose Write. Writing and checking the SSD took approx. 5 min. This installed Debian Bullseye with desktop environment and recommended applications.
I then removed the SD card from the Pi and attached the SSD to the lower blue USB port (middle). I attached a screen and keyboard/mouse and plugged in the power cable. When the bootloader found no SD card, it booted from the SSD after a five seconds. On the desktop, I adjusted preferences before continuing.
Open a terminal and type the following command to find the ip-address of the Raspberry Pi:
hostname -I
With the following command, you can check the CPU-temperature:
vcgencmd measure_temp
And find the Raspberry Pi OS version you are running:
lsb_release -a
In my case:
Release: 11
Codename: bullseye (04/2022)
Find your storage adapter chipset:
sudo lsusb
Mine gives the following result: JMicron USA Techology Corp. USB3.0 to SATA adapter
Mosquitto MQTT Broker installation
Next, we have to install a Mosquitto Broker on the Pi. Open a terminal and type:
sudo apt install mosquitto mosquitto-clients
During the installation process, the package manager will automatically configure the Mosquitto broker to start on boot. We can check that the service is already running:
sudo systemctl status mosquitto
We have to modify the config-file to give our ESP8266 loggers access without credentials:
sudo nano /etc/mosquitto/mosquitto.conf
Scroll to the end of the file and add the following two lines:
listener 1883
allow_anonymous true
Then, press CTRL-X to exit and save the file. Press Y and Enter. You have to reboot for the changes to take effect:
sudo reboot
Download and install MQTT Explorer on your laptop. Start the program and try to access mosquitto broker on the Pi. Use the IP address of the Pi and Port 1883. Leave username and password blank and connect. If MQTT Explorer manages to connect, mosquitto is correctly set-up and running.
Node-RED installation
Node-RED was part of the Full OS install. We just have to set it up to start automatically at boot:
sudo systemctl enable nodered.service
sudo reboot
Now, open a browser on your laptop and go to the IP address of the Pi, port 1880, type for example:
192.168.1.33:1880
The Node-RED Flow window should appear. From the menu in the top right-hand corner, choose: Manage Palette.
Choose Palette -> Install. Search and install the following three packages:
node-red-dashboard
node-red-contrib-ams-decoder
node-red-contrib-influxdb
InfluxDB time-series database installation
Jonathan Oxer has provided a write-up that I try to follow. A second guide was written by Simon Hearne:
Start by getting the official repository key:
wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -
Ignore the depreciated warning and continue:
For Raspian bullseye:
echo "deb https://repos.influxdata.com/debian bullseye stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
Update the list of available packages:
sudo apt update
Install InfluxDB:
sudo apt install influxdb
The terminal log below shows the whole installation process:
pi@raspberrypi:~ $ wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
pi@raspberrypi:~ $ echo "deb https://repos.influxdata.com/debian bullseye stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
deb https://repos.influxdata.com/debian bullseye stable
pi@raspberrypi:~ $ sudo apt update
Hit:1 http://raspbian.raspberrypi.org/raspbian bullseye InRelease
Get:2 https://repos.influxdata.com/debian bullseye InRelease [4,739 B]
Hit:3 http://archive.raspberrypi.org/debian bullseye InRelease
Get:4 https://repos.influxdata.com/debian bullseye/stable armhf Packages [781 B]
Fetched 5,520 B in 1s (5,262 B/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
34 packages can be upgraded. Run 'apt list --upgradable' to see them.
pi@raspberrypi:~ $ sudo apt install influxdb
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
libfuse2
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
influxdb
0 upgraded, 1 newly installed, 0 to remove and 34 not upgraded.
Need to get 50.7 MB of archives.
After this operation, 135 MB of additional disk space will be used.
Get:1 https://repos.influxdata.com/debian bullseye/stable armhf influxdb armhf 1.8.10-1 [50.7 MB]
Fetched 50.7 MB in 5s (10.6 MB/s)
Selecting previously unselected package influxdb.
(Reading database ... 175151 files and directories currently installed.)
Preparing to unpack .../influxdb_1.8.10-1_armhf.deb ...
Unpacking influxdb (1.8.10-1) ...
Setting up influxdb (1.8.10-1) ...
Created symlink /etc/systemd/system/influxd.service → /lib/systemd/system/influxdb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/influxdb.service → /lib/systemd/system/influxdb.service.
Processing triggers for man-db (2.9.4-2) ...
pi@raspberrypi:~ $
Tell the systemctl service manager to enable InfluxDB at startup:
sudo systemctl unmask influxdb
sudo systemctl enable influxdb
Start influxdb manually this time:
sudo systemctl start influxdb
Now we can start the influx client:
influx
Here is a link to the InfluxDB getting started documentation. We need to create and use a database:
pi@raspberrypi:~ $ influx
Connected to http://localhost:8086 version 1.8.10
InfluxDB shell version: 1.8.10
> CREATE DATABASE home
> SHoW DATABASES
name: databases
name
----
_internal
home
> USE home
Using database home
> exit
pi@raspberrypi:~ $
Grafana dashboard installation
We follow the guides of Jonathan and Simon linked above. Again we need to add the Grafana packages to apt:
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
Ignore the depreciated warning and continue:
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
Update the package list and install the Grafana package:
sudo apt update
sudo apt install grafana
Make Grafana run automatically at startup plus manually start it this time:
sudo systemctl unmask grafana-server.service
sudo systemctl enable grafana-server.service
sudo systemctl start grafana-server
The terminal log pasted below shows the whole installation:
pi@raspberrypi:~ $ wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
pi@raspberrypi:~ $ echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
deb https://packages.grafana.com/oss/deb stable main
pi@raspberrypi:~ $ sudo apt update
Hit:1 http://archive.raspberrypi.org/debian bullseye InRelease
Hit:2 http://raspbian.raspberrypi.org/raspbian bullseye InRelease
Hit:3 https://repos.influxdata.com/debian bullseye InRelease
Get:4 https://packages.grafana.com/oss/deb stable InRelease [12.1 kB]
Get:5 https://packages.grafana.com/oss/deb stable/main armhf Packages [33.7 kB]
Fetched 45.8 kB in 1s (32.5 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
34 packages can be upgraded. Run 'apt list --upgradable' to see them.
pi@raspberrypi:~ $ sudo apt install grafana
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
libfuse2
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
grafana
0 upgraded, 1 newly installed, 0 to remove and 34 not upgraded.
Need to get 74.0 MB of archives.
After this operation, 243 MB of additional disk space will be used.
Get:1 https://packages.grafana.com/oss/deb stable/main armhf grafana armhf 8.5.1 [74.0 MB]
Fetched 74.0 MB in 8s (9,518 kB/s)
Selecting previously unselected package grafana.
(Reading database ... 175176 files and directories currently installed.)
Preparing to unpack .../grafana_8.5.1_armhf.deb ...
Unpacking grafana (8.5.1) ...
Setting up grafana (8.5.1) ...
Adding system user `grafana' (UID 118) ...
Adding new user `grafana' (UID 118) with group `grafana' ...
Not creating home directory `/usr/share/grafana'.
### NOT starting on installation, please execute the following statements to configure grafana to start automatically using systemd
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable grafana-server
### You can start grafana-server by executing
sudo /bin/systemctl start grafana-server
pi@raspberrypi:~ $ sudo systemctl unmask grafana-server.service
pi@raspberrypi:~ $ sudo systemctl enable grafana-server.service
Synchronizing state of grafana-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable grafana-server
Created symlink /etc/systemd/system/multi-user.target.wants/grafana-server.service → /lib/systemd/system/grafana-server.service.
pi@raspberrypi:~ $ sudo systemctl start grafana-server
pi@raspberrypi:~ $
Now, open a browser on your laptop and go to the IP address of the Pi, port 3000, type for example:
192.168.1.33:3000
The Grafana log-in screen should appear. Log in with user: admin, password: admin and change your password!
Now choose: Configuration -> Data Sources -> Add Data Source
Fill in: URL: http://localhost:8086
Database: home
and press: SAVE&TEST
Now you should see: Data source is working
© 2022 notthemarsian