ironsheep / RPi-Reporter-MQTT2HA-Daemon

Linux service to collect and transfer Raspberry Pi data via MQTT to Home Assistant (for RPi Monitoring)
GNU General Public License v3.0
441 stars 62 forks source link

RaspberryPi 5 - notes #113

Open bsimmo opened 8 months ago

bsimmo commented 8 months ago

Ok less a bug release, just a place I'm going to put any note when I test it on the Pi5 in a little bit I do know we can add more detail, voltages, fan speed etc.

Bookworm may cause a problem due to the way we need to set it up ( venv and python.) but that's Pi independent.

bsimmo commented 8 months ago

I forgot to add some, install isn't much different a few tweaks (simpler) iirc. Sems to show everything we need.

We can now also show if a 5V 5A PSU is being used (or 3A is being overridden) We can show the 5V voltage. (and many others).

ironsheep commented 7 months ago

Yep, I'm learning venv setup and will adjust my instructions when I figure out a good approach.

Which would you see using more? a per-user setup for venv or a per project setup?

sholdee commented 6 months ago

I created a venv under /opt/RPi-Reporter-MQTT2HA-Daemon, activated the venv, installed requirements, and set isp-rpi-reporter.service as such:

WorkingDirectory=/opt/RPi-Reporter-MQTT2HA-Daemon/
ExecStart=/opt/RPi-Reporter-MQTT2HA-Daemon/venv/bin/python3 -u /opt/RPi-Reporter-MQTT2HA-Daemon/ISP-RPi-mqtt-daemon.py

Has been working great. I prefer having it in a virtual environment.

ironsheep commented 6 months ago

@sholdee I can easily make that change and update the docs. Thank you for finding, testing, and reporting this working pattern!

3VAbdAVE commented 5 months ago

Gonna expand on @sholdee 's comment.

This has become more important with Bookworm, since Python 3.11 defaults to failing pip installs without a "--break-system-packages" argument, and that's kinda (intentionally) scary for someone running the install. I've just got this working in a venv, here's my instruction updates:

First, I'd probably remove the duplicate packages entirely and use entirely env local packages. I had a couple conflicts between my own apps and this daemon due to system packages. So put all the requirements into the Python venv, and reduce the OS system instruction to sudo apt update && sudo apt install -y git python3 python3-pip python3-venv python3-apt

Add the others to requirements.txt. Pip install should take care of dependencies.

This is actually pretty easy, since the virtual environment gets baked in when launched from the venv symlinks.

Create the venv as root: sudo python -m venv /opt/RPi-Reporter-MQTT2HA-Daemon

I like to put the actual python application into a subfolder to keep the venv clean, "app" in this case: sudo git clone https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon.git /opt/RPi-Reporter-MQTT2HA-Daemon/app

This is just what I'm using, you might prefer a different pattern.

Install the requirements: sudo /opt/RPi-Reporter-MQTT2HA-Daemon/bin/pip install -r /opt/RPi-Reporter-MQTT2HA-Daemon/app/requirements.txt

(This worked fine on my systems as-is, it's possible there's some additional system packages needed for pip to do it's thing. Sometimes it can't auto-resolve dependencies, or the wheels need to compile, etc.)

Modify the .service file to execute under the virtualenv. (Ideally this gets updated if you decide to use venvs for future versions.) sudo sed -i '/^ExecStart=/ s/usr\/bin/opt\/RPi-Reporter-MQTT2HA-Daemon\/bin/; s/ISP-RPi-mqtt-daemon.py/app\/ISP-RPi-mqtt-daemon.py/; /^WorkingDirectory/ s/$/app\//' /opt/RPi-Reporter-MQTT2HA-Daemon/app/isp-rpi-reporter.service

Edit the config.ini as appropriate and set permissions, since it contains the mqtt password. (The default service file runs this as the daemon user.)

sudo chown root:daemon /opt/RPi-Reporter-MQTT2HA-Daemon/app/config.ini
sudo chmod 640 /opt/RPi-Reporter-MQTT2HA-Daemon/app/config.ini

Install the service file and kick it off:

sudo mkdir -p /usr/local/lib/systemd/system/
sudo ln -s /opt/RPi-Reporter-MQTT2HA-Daemon/app/isp-rpi-reporter.service /usr/local/lib/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now isp-rpi-reporter.service

Since the service runs as daemon, I had errors with files in /dev on one or two systems. In my case, I added daemon to the video group, but you can also just set the service file to run as root. w/e works in your env.

pskowronek commented 5 months ago

[ Awaiting the update regarding venv :) ]

btw, on Bookworm (RPi 4) this package is not installed by default: libraspberrypi-bin