Skip to content

3. Full install procedure for the Raspberry Pi

Graham Ross edited this page Oct 31, 2022 · 34 revisions

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.

3.1 Full installation on a Raspberry Pi using IOTStack.

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.

Raspberry Pi setup

  1. Download the Raspberry Pi Imager found at https://www.raspberrypi.com/software/

  2. Erase the SD card using the Raspberry Pi Imager.

  3. Select the Raspberry Pi OS (32-bit) or the Raspberry Pi OS Lite (32-bit, no desktop).

  4. 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 the pi username.

  5. Flash the image onto a A2 class SD card.

  6. Install sd card into rpi and power it up.

  7. Wait a few minutes for the Pi to boot up for the first time.

  8. 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.

  9. 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.

  10. You can also try nslookup battery on windows to see the Pi's IP address.

  11. Log in using ssh pi@battery.local or ssh pi@192.168.?.? (password from step 4) (see note 2)

  12. run sudo raspi-config

  13. 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.

Update the OS

sudo apt update 
sudo apt upgrade -y
sudo reboot now 
  • login again with ssh pi@battery.local

Setup IOTstack:

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.

  1. Create the docker group if it does not exist.
    sudo groupadd docker 
    
  2. Add the current user to the docker group.
    sudo usermod -aG docker $USER
    
  3. 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 installation:

  • ( 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

Get PylonToMQTT:

  1. Download the code from github
    cd ~
    wget https://github.com/ClassicDIY/PylonToMQTT/archive/refs/heads/main.zip
    
  2. Extract the zip file:
    unzip main.zip
    
  3. Copy the compose-override.yml file to IOTStack
    cp ~/PylonToMQTT-main/Code/Python/compose-override.yml ~/IOTstack
    

Run IOTStack to create the containers:

cd ~/IOTstack
./menu.sh

Select the other required containers

  • 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 Build Stack log

  • exit menu.sh and run docker ps

  • You should see the following docker containers Build Stack log

3.3 Setup telegraf:

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
    

3.4 Access Portainer-ce:

(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 Build Stack log

  • If everything works the PylonToMQTT logs should look like the following; Build Stack log

3.5 Setup grafana:

  • 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

3.6 Troubleshooting:

  • 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 Build Stack log

  • Subscribe to PylonToMQTT/#

  • You should see the following messages from PylonToMQTT Build Stack log