diff --git a/tools/rpi/README.md b/tools/rpi/README.md index c5818a3a..249e68d7 100644 --- a/tools/rpi/README.md +++ b/tools/rpi/README.md @@ -138,7 +138,7 @@ python3 -m pip list #watch for RF24 module - if its there its installed ``` -Alternative install pyRF24 library on Debian 11 (bullseye) 64 bit operating system +Alternative: Install pyRF24 library on Debian 11 (bullseye) 64 bit operating system ----------------------------------------------------------------------------------- The description above does not work on Debian 11 (bullseye) 32 bit operating system. Please check first, if you have Debian 11 (bullseye) 64 bit operating system installed: @@ -163,21 +163,26 @@ Please check first, if you have Debian 11 (bullseye) 64 bit operating system ins - `lsb_release -d` - `cat /etc/debian_version` -Attension (PYTHON error ?): Debian 12 follows the recommendation of `PEP 668` -see: `https://peps.python.org/pep-0668/` - now PYTHON is configured as +Important: Debian 12 follows the recommendation of [`PEP 668`] +(https://peps.python.org/pep-0668/) - now, PYTHON is configured as "externally-managed-environment" ! +- You cann't install python libs via `pip`! +- You have to use a python virtual environment `https://docs.python.org/3/library/venv.html` ```code sudo apt install cmake git python3-dev libboost-python-dev python3-pip python3-rpi.gpio +cd ~ +python3 -m venv ahoyenv ## create python virtual environment +source ahoyenv/bin/activate ## activate the virtual environment + git clone --recurse-submodules https://github.com/nRF24/pyRF24.git cd pyRF24 - python3 -m venv ahoyenv - source ahoyenv/bin/activate python3 -m pip install . -v -cd + python3 -m pip list ## check: search for pyRF24 +cd ~ ``` Required python modules @@ -195,10 +200,10 @@ Configuration Local settings are read from ahoy.yml An example is provided as ahoy.yml.example -If you have problems with your radio module from ahoi, +If you have any problems with your radio module, e.g.: cannot interpret received data, please try to reduce the speed of your radio module! -Add the following parameter to your ahoy.yml configuration file in "nrf" section: +Add the following parameter to your `ahoy.yml` configuration file in section `nrf`: `spispeed: 600000` (0.6 MHz) @@ -210,12 +215,14 @@ contact the inverter every second on channel 40, and listen for replies. Whenever it sees a reply, it will decoded and logged to the given log file. - $ sudo python3 -um hoymiles --log-transactions --verbose --config /home/dtu/ahoy.yml | tee -a log2.log + ~~$ sudo python3 -um hoymiles --log-transactions --verbose --config /home/dtu/ahoy.yml | tee -a log2.log + $ tail -f RPI-AHOY-DTU.log & + $ python3 -um hoymiles --log-transactions --verbose --config /home/dtu/ahoy.yml Python parameters - `-u` enables python's unbuffered mode - `-m hoymiles` tells python to load module 'hoymiles' as main app - +Do not forget to stop `tail -f ...` The application describes itself ```code @@ -259,12 +266,20 @@ Example injects exactly the same as we normally use to poll data This allows for even faster hacking during runtime -Running it as a service + +Run as a service ----------------------- -If you want to run directly from the start, you might want to install it as a service. -Depending on if you want to run it once a user is logged in or as soon as the system is booted, two service examples are included. -ahoy.service allows you to start it as a user service upon login. -ahoy_system.service allows you to start it as a system service already before login without user interaction. +If you want to run directly at start, you have to install ahoy as a service. +Depending oni, if you want to run it once a user is logged in or as soon as the system is booted, +two service examples are included. +-`ahoy.service` allows you to start it as a user service upon login. +-`ahoy_system.service` allows you to start it as a system service already before login without user interaction. + +Run as a service on Debian 12 (bookworm) +---------------------------------------- +-`ahoy@bookworm.service` allows you to start it as a user service upon login. +-`ahoy@bookworm_system.service` allows you to start it as a system service already before login without user interaction. + Analysing the Logs ------------------ @@ -283,8 +298,6 @@ Use basic command line tools to get an idea what you recorded. For example: A brief example log is supplied in the `example-logs` folder. - - Todo ---- @@ -298,7 +311,6 @@ Todo - ... - References ---------- diff --git a/tools/rpi/ahoy.service b/tools/rpi/ahoy.service new file mode 100644 index 00000000..c7be5bb2 --- /dev/null +++ b/tools/rpi/ahoy.service @@ -0,0 +1,35 @@ +###################################################################### +# systemd.service configuration for ahoy (lumapu) +# users can modify the lines: +# Description +# ExecStart (example: name of config file) +# WorkingDirectory (absolute path to your private ahoy dir) +# To change other config parameter, please consult systemd documentation +# +# To activate this service, enable and start ahoy.service +# $ systemctl --user enable $(pwd)/ahoy/tools/rpi/ahoy.service +# $ systemctl --user status ahoy +# $ systemctl --user start ahoy +# $ systemctl --user status ahoy +# +# 2023.01 +###################################################################### + +[Unit] + +Description=ahoy (lumapu) as Service +After=network.target local-fs.target time-sync.target + +[Service] +ExecStart=/usr/bin/env python3 -um hoymiles --log-transactions --verbose --config ahoy.yml +RestartSec=10 +Restart=on-failure +Type=simple + +# WorkingDirectory must be an absolute path - not relative path +WorkingDirectory=/home/pi/ahoy/tools/rpi +EnvironmentFile=/etc/environment + +[Install] +WantedBy=default.target + diff --git a/tools/rpi/ahoy@bookworm.service b/tools/rpi/ahoy@bookworm.service new file mode 100644 index 00000000..2dff3637 --- /dev/null +++ b/tools/rpi/ahoy@bookworm.service @@ -0,0 +1,37 @@ +###################################################################### +# systemd.service configuration for ahoy (lumapu) +# users can modify the lines: +# Description +# ExecStart (example: name of config file) +# WorkingDirectory (absolute path to your private ahoy dir) +# To change other config parameter, please consult systemd documentation +# +# To activate this service, enable and start ahoy.service +# $ systemctl --user enable /home/pi/ahoy/tools/rpi/ahoy@bookworm.service +# $ systemctl --user status ahoy@bookworm.service +# $ systemctl --user start ahoy@bookworm.service +# $ systemctl --user stop ahoy@bookworm.service +# $ systemctl --user disable ahoy@bookworm.service +# +# 2023.01 +# 2024.01 +###################################################################### + +[Unit] +Description=ahoy (lumapu) as Service + +[Service] +ExecStart=/bin/bash -c '\ + source /home/pi/ahoyenv/bin/activate; \ + python3 -um hoymiles --log-transactions --verbose --config ahoy.yml' +RestartSec=30 +Restart=on-failure +Type=simple + +# WorkingDirectory must be an absolute path - not relative path +WorkingDirectory=/home/pi/ahoy/tools/rpi +EnvironmentFile=/etc/environment + +[Install] +WantedBy=default.target + diff --git a/tools/rpi/ahoy@bookworm_system.service b/tools/rpi/ahoy@bookworm_system.service new file mode 100644 index 00000000..3bbfa647 --- /dev/null +++ b/tools/rpi/ahoy@bookworm_system.service @@ -0,0 +1,46 @@ +###################################################################### +# systemd.service configuration for ahoy (lumapu) +# users can modify the lines: +# Description +# ExecStart (example: name of config file) +# WorkingDirectory (absolute path to your private ahoy dir) +# To change other config parameter, please consult systemd documentation +# +# To activate this service, enable and start ahoy.service: +# - Create folder ahoy in /home/ and set owner to the user that the +# service should be executed for (e.g. pi) +# - Copy folder contents to new folder +# - Adjust the user that this service should be executed as, avoid root +# - Execute commands to setup, check and start/stop as wanted +# $ sudo systemctl enable /home/ahoy/tools/rpi/ahoy@bookworm_system.service +# $ sudo systemctl status ahoy@bookworm_system +# $ sudo systemctl start ahoy@bookworm_system +# $ sudo systemctl stop ahoy@bookworm_system +# $ sudo systemctl disable ahoy@bookworm_system +# +# 2023.01 +# 2023.03 +# 2024.01 +###################################################################### + +[Unit] + +Description=ahoy (lumapu) as Service +After=network.target local-fs.target time-sync.target + +[Service] +ExecStart=/bin/bash -c '\ + source /home/pi/ahoyenv/bin/activate; \ + python3 -um hoymiles --log-transactions --verbose --config ahoy.yml' +RestartSec=30 +Restart=on-failure +Type=simple +User=pi + +# WorkingDirectory must be an absolute path - not relative path +WorkingDirectory=/home/ahoy/tools/rpi +EnvironmentFile=/etc/environment + +[Install] +WantedBy=default.target +