Finally, the fun part.
In this guide, I will be using code blocks to show you what to enter into the command line interface (CLI), illustrated below.
sudo example-code-block -butts # stuff prefixed with a hash is my comments
When a code block like this appears, it means that you have to enter each line individually into your CLI and hit enter.
I might add notes, just for you, which are prefaced with the hash symbol (#) – don’t put these into the CLI if you can help it.
Wanna skip ahead?
Part 1 : Hardware configuration
Part 2 : Installing software
Part 3 : Configuring Grafana
Part 4 : Credits and final thoughts
Changing your password, and enabling SSH
First we need to connect your Pi4 to your Wifi network, using the little Wifi icon on the taskbar. Select your network SSID, and enter your password.
Next we need to change your Pi4’s user password from the default, and turn on SSH so we can do the rest of the hard work from the comfort of your personal computer.
Once we get through these early stages of setting up the Pi4, you’ll be using PuTTY to access your Pi4 remotely using SSH, so you should probably install in on your PC.
Now, open the Pi4’s CLI (called terminal)
Change your password:
sudo raspi-config #hit enter passwd #you will be prompted to enter your password. #For the purposes of this tutorial I'll use 123456 - but please, for the love of god, use something a little harder to crack. # Do it, and hit enter. # You need to do this so that you're not hacked immediately once we enable SSH.
Pi4 username and password is now Pi/1234.
Turn on SSH:
sudo systemctl enable ssh sudo systemctl start ssh
Find out your Pi’s IP address
It’s a very good idea to write this IP address down somewhere, as we’ll be referring to it often.
Head back to your computer, and install PuTTY.
Open PuTTY, and create a new connection by;
- Entering your Pi4’s IP address in the Host Name box (our example uses 10.7.0.47)
- Typing Pi (or whatever you want) in the Saved Sessions box.
- Hit “Save”, so you don’t have to type the IP address again in the future.
- Either double click the now saved Pi session, or make sure it’s selected and click on “Open”
You’ll now be presented with a CLI window, asking for your username.
The CLI will now ask you for your password, this is the password we set earlier, as an example we used 1234.
then hit enter again (the password text won’t be displayed).
Updating everything on your before we go on.
On the now logged-in and authenticated PuTTY terminal, enter the following:
sudo apt-get update sudo apt-get upgrade -y
If at any stage through this tutorial the CLI asks for confirmation to install/update, type Y and hit enter.
sudo apt-get install -y apt-transport-https sudo apt-get install -y software-properties-common wget 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 # that paragraph above is all a single line sudo systemctl enable --now grafana-server sudo /bin/systemctl daemon-reload sudo /bin/systemctl enable grafana-server sudo /bin/systemctl start grafana-server systemctl status grafana-server.service sudo apt -y install ufw sudo ufw enable sudo ufw allow ssh sudo ufw allow 3000/tcp #enter admin and admin for default username, (Default will need to be reset after first login.)
Check to make sure Grafana is working
Open your PC’s web browser, and enter the IP address of your Pi4 into your URL bar, suffixed with :3000 – ie, 10.7.0.47:3000
You’ll be asked to choose a new password, for this example we’ll choose 123456.
Grafana username and password is now admin/123456.
get -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add - source /etc/os-release echo "deb https://repos.influxdata.com/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/influxdb.list sudo apt-get update && sudo apt-get install influxdb sudo service influxdb start sudo systemctl enable --now influxdb #enable and run on system boot sudo systemctl status influxdb #check status #hit ctrl-c to close sudo ufw allow 8086/tcp #This command will open the default port for Influxdb
Create InfluxDB Database for your Batrium data.
influx #type 'influx' you will notice a different CLI prompt. This is normal, you are now in the influx CLI. create database batrium create user batrium with password '123456' grant all on batrium to batrium show databases show users exit influx -username 'batrium' -password '123456' -database batrium exit
Congratulations, you now have an empty Batrium database!
InfluxDB username and password is now batrium/123456.
get -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -source /etc/os-release echo "deb https://repos.influxdata.com/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/influxdb.list sudo apt-get update && sudo apt-get install influxdb sudo apt install nodejs nodejs -v sudo apt install npm sudo npm install -g --unsafe-perm node-red node-red-admin sudo ufw allow 1880 sudo ufw allow 18542/udp #Opening this port allows Node-Red to "listen" for the data from the Batrium node-red #This starts node-red.
Check to make sure node-red is working
Open your PC’s web browser, and enter the IP address of your Pi4 into your URL bar, suffixed with :1880– ie, 10.7.0.47:1880
Tell node-red to boot on startup.
sudo nano /etc/systemd/system/node-red.service # this should open up a different graphical interface in your CLI, paste in the following . [Unit] Description=Node-RED After=syslog.target network.target [Service] ExecStart=/pi/local/bin/node-red Restart=on-failure KillSignal=SIGINT # log output to syslog as 'node-red' SyslogIdentifier=node-red StandardOutput=syslog # non-root user to run as WorkingDirectory=/home/pi/ User=pi Group=pi [Install] WantedBy=multi-user.target #once you have pasted in the text above, hit: ctrl-o #this saves the file ctrl-x #this exits the file sudo systemctl enable node-red sudo systemctl start node-red sudo systemctl stop node-red #Reboot and test to ensure node-red starts up.
Installing binary-parser, required by node-red.
#Navigate to your Node-Red install folder. sudo -i cd /home/pi/.node-red #substitute 'pi' for you current Linux user. npm install binary-parser #We now need to edit our Node-Red settings.js file to enable the binary-parser sudo nano /home/pi/.node-re/settings.js #again substitute 'pi' for your current linux user. #this will open up a blue text editor screen with a lot of information. You need to add some text after the following line: "functionGlobalContext:" #This line can be found if you hit "page-down" on your keyboard around six or seven times. It's annoying. binary_parser:require('binary-parser').Parser, ctrl-o ctrl-X Y enter
Importing the Batrium flow into node-red
Open Node-Red in your PC web browser.
IP address of your Pi4 into your URL bar, suffixed with :1880- ie, 10.7.0.47:1880
In the top-right menu icon, click on Manage palette.
You need to install two new palettes (plug-ings, basically)
Put these two palette names into the install tab search box, and click on “install“. Accept any prompts that come up.
Click HERE to copy the Batrium flow JSON
Import Batrium flow json by clicking the top right menu icon, then click on import.
Past the Batrium JSON file, import to “new flow”, and click “import”
Your node-red flow should look something like this.
Of note here is that this flow is set up to listen for the Batrium UDP data on port 18542. We opened up this UDP port during the Node-Red install. This flow is also set up for a string of 16 longmons. If you have more, you will need to edit some of the nodes to reflect this.
Feel free to hit the big red deploy button!
Now we need to Deploy the Node-Red flow and check the debug tab for any errors. If you see some “TypeErrors” then it is usually because the Binary-Parser was not installed correctly. Also, you can toggle the green msg.payload debug filters on and off to see the data being received in the debug window.