Here a list of common procedures to test and run this script to a remote machine:
- Copy sources to remote machine
- Prepare remote machine (only once)
- Run on remote machine
- Monitor DBus from 2nd shell
- Configure SSH keys to avoid password usage
- Connect and create dir into remote machine
$ ssh pi@raspberrypi.local
(rpi)$ mkdir -p dev/fw_victron
(rpi)$ exit- Copy local sources to remote machine
$ rsync -av --exclude venv --exclude logs --exclude __pycache__ --exclude .git -e ssh * pi@raspberrypi.local:/home/pi/dev/fw_victron- Connect to remote machine
$ ssh pi@raspberrypi.local- Install requirements (only once)
(rpi)$ sudo apt-get install python3 python3-pip libcairo2-dev libgirepository1.0-dev dbus-x11- Install python's requirements (only once)
(rpi)$ cd dev/fw_victron
(rpi)$ python -m venv venv # Optional: only for venv support
(rpi)$ source venv/bin/activate # Optional: only for venv support
(rpi-venv)$ pip install -r requirements.txt- Connect to remote machine and cd to firmware dir
$ ssh pi@raspberrypi.local
(rpi)$ cd dev/fw_victron- Init DBus session (only if required)
(rpi)$ env | grep DBUS_SESSION_BUS_ADDRESS
# no response means the DBus session is required
(rpi)$ exec dbus-run-session -- bash
(rpi)$ env | grep DBUS_SESSION_BUS_ADDRESS
# copy the printed output as DBUS Session- Activate the venv (if required)
(rpi)$ source venv/bin/activate- Run the Python script
(rpi)$ python run.py- Connect to remote machine with another shell
$ ssh pi@raspberrypi.local- Set DBus session, using the value copied after his creation
(rpi2)$ export DBUS_SESSION_BUS_ADDRESS=unix:path=/tmp/dbus-Qzp4nPaFAr,guid=88e4d61b4af3628519f04ede651e6f7f- Start the dbus monitor
(rpi2)$ dbus-monitor- Create a 'public_keys' on the remote machine
$ ssh pi@raspberrypi.local
(rpi)$ mkdir -p .ssh/public_keys
(rpi)$ exit- Generate a new key pair and copy the public one on the remote machine
$ ssh-keygen -t rsa
# save it in /home/USER/.ssh/id_rsa_for_rpi
$ scp /home/USER/.ssh/id_rsa_for_rpi.pub pi@raspberrypi.local:/home/pi/.ssh/public_keys- Set up the new public key into remote machine
$ ssh pi@raspberrypi.local
(rpi)$ cat .ssh/pub_keys/id_rsa_for_rpi.pub >> .ssh/authorized_keys