-
Notifications
You must be signed in to change notification settings - Fork 6
3. Full install procedure for the Raspberry Pi
The python implementation of PylonToMQTT allows you to run everything on a Raspberry Pi including mosquitto, telegraf, InfluxDB and Grafana.
- PylonToMQTT: Reads serial data from the battery console port and publishes the results to an MQTT Broker.
- Mosquitto: MQTT broker
- Telegraf: MQTT subscriber that sends data to InfluXDB
- InfluxDB: Time series database used by Grafana
- Grafana: Graphical interface.
If you simply want to add PylonToMQTT to an existing Raspberry Pi setup that already has the above containers, perform the steps in section 4.
The following instructions describe how to setup a Raspberry Pi with the required components to make use of the PylonToMQTT app.
- Flash and update the Raspberry Pi.
- Setup IOTstack.
- Setup and configure the required container along with pylon_to_mqtt using IOTStack
- Configure Telegraf and Grafana.
-
Download the Raspberry Pi Imager found at https://www.raspberrypi.com/software/
-
Erase the SD card using the Raspberry Pi Imager.
-
Select the Raspberry Pi OS (32-bit) or the Raspberry Pi OS Lite (32-bit, no desktop).
-
Press the gear icon and set the hostname to
battery
, enable SSH with password authentication, or public key (see note 1 below), set the password for thepi
username. -
Flash the image onto a A2 class SD card.
-
Install sd card into rpi and power it up.
-
Wait a few minutes for the Pi to boot up for the first time.
-
If you have a mdnsResponder like the Bonjour service running on your network, you can access your pi using it's hostname.local otherwise you will have to find your Pi's IP address using your router or an IP scanner tool. The rest of this document will use battery.local, you can use the IP address instead.
-
On Windows, you can use the Command Prompt or Power Shell for the following commands. I use the Windows terminal to setup tabs to ssh to each device on my network.
-
You can also try
nslookup battery
on windows to see the Pi's IP address. -
Log in using
ssh pi@battery.local
orssh pi@192.168.?.?
(password from step 4) (see note 2) -
run
sudo raspi-config
-
select update then Finish when done (you can also setup Wifi at this point), the pi might reboot depending on the update.
-
note 1: to use passwordless SSH access copy your public key to the Set authorized_keys for 'pi': (see www.raspberrypi.org/documentation/remote-access/ssh/).
-
note2: if you have previously connected to your pi using ssh with a different image, you may need to delete the entry in your %HOMEPATH%.ssh\known_hosts file that refers to your pi's IP address. From the command prompt on windows, run:
notepad %HOMEPATH%\.ssh\known_hosts
delete the line with your pi's IP or with the battery.local hostname.
sudo apt update
sudo apt upgrade -y
sudo reboot now
- login again with
ssh pi@battery.local
The benefit of using IOTStack is that it makes it easy to include other docker images like InfluxDB, Telegraf, Portainer-ce and Grafana.
Before setting up IOTStack and docker, create a new group called docker and add the current user to the docker group.
- Create the docker group if it does not exist.
sudo groupadd docker
- Add the current user to the docker group.
sudo usermod -aG docker $USER
- Log in to the new docker group (to avoid having to log out / log in again; but if not enough, try to reboot):
newgrp docker
-
( IOTStack Wiki available at:` https://sensorsiot.github.io/IOTstack/Basic_setup/ )
cd ~ sudo apt install -y curl
curl -fsSL https://raw.githubusercontent.com/SensorsIot/IOTstack/master/install.sh | bash
say yes to everything
-
Required patches as per IOTstack documentation;
sudo bash -c '[ $(egrep -c "^allowinterfaces eth\*,wlan\*" /etc/dhcpcd.conf) -eq 0 ] && echo "allowinterfaces eth*,wlan*" >> /etc/dhcpcd.conf'
echo $(cat /boot/cmdline.txt) cgroup_memory=1 cgroup_enable=memory | sudo tee /boot/cmdline.txt
sudo reboot now
-
login again with
ssh pi@battery.local
- Download the code from github
cd ~ wget https://github.com/ClassicDIY/PylonToMQTT/archive/refs/heads/main.zip
- Extract the zip file:
unzip main.zip
- Copy the compose-override.yml file to IOTStack
cp ~/PylonToMQTT-main/Code/Python/compose-override.yml ~/IOTstack
cd ~/IOTstack
./menu.sh
-
select Build Stack
-
Select the following containers to build using the space bar;
grafana
influxdb
mosquitto
portainer-ce
telegraf
-
Press enter when done.
-
select Docker Commands and then Start stack.
-
You should see the following logs
-
exit menu.sh and run
docker ps
-
You should see the following docker containers
sudo cp ~/PylonToMQTT-main/Code/Python/telegraf.conf ~/IOTstack/volumes/telegraf/
docker container restart telegraf
-
Plug in battery cable to one of the pi's USB ports. Restart the pylon_to_mqtt container
docker container restart pylon_to_mqtt
(IOTStack documentation https://sensorsiot.github.io/IOTstack/Containers/Portainer-ce/)
docker container restart portainer-ce
-
Browse battery.local:9000
-
Create an admin User & Password
-
Select: Docker (Manage the local Docker environment)
-
Connect
-
Select Containers from the Portainer Dashboard and click the logs Quick Actions Icon
-
If everything works the PylonToMQTT logs should look like the following;
-
Browse battery.local:3000
-
Use admin/admin as the default username/password, set a new password
-
Create a new InfluxDB datasource
URL:
http://influxdb:8086
Database:
mqtt_pylon
User:
dba
Password:
supremo
HTTP Method: GET
Save & Test
-
Import sample dashboard via grafana.com
In Grafana, goto dashboards->+ Import.
Paste the following URL into "Import via grafana.com"
https://grafana.com/grafana/dashboards/17305
Press "Load"
Select the InfluDb data source
then Press "Import"
Save dashboard when you're done.
!! now you can edit/duplicate/remove panels to customize the dashboard for your setup.
At this point you might want to see some (video tutorials) on Grafana
-
Connect to MQTT broker using MQTTfx to see the data PylonToMQTT is publishing.
-
Download and install MQTT.fx
-
Connect to the MQTT broker using battery.local (or the Pi's IP) and the port 1883
-
Subscribe to PylonToMQTT/#
-
You should see the following messages from PylonToMQTT