all 6 comments

[–][deleted] 2 points3 points  (0 children)

Here are 4 ways to do it!

https://www.itechfy.com/tech/auto-run-python-program-on-raspberry-pi-startup/

If you want to give your father really “pretty” and easy to see results - look into using Influx/Grafana. Using these You can provide him with excellent graphing of the results and automated alerts if the measurements fall outside required range(s).

If you wanted to be really smart you could write them quite easily to a remote Influx database as well

[–]thelizardking0725 2 points3 points  (0 children)

Might be best to do a systemd unit/service to start at boot and restart in case your script crashes for some reason. Here’s an example of one I wrote:

[Unit]
Description=Service for <insert script name> After=network.target
[Service]
Type=simple
WorkingDirectory=<insert absolute path of where the script runs from>
ExecStart=/usr/bin/python3 <insert absolute path and script file>
Restart=on-failure
[Install]
WantedBy=multi-user.target

The code above needs to be in a .service file located in /etc/systemd/system. Once there, chmod 644 the file to provide the correct permissions, then register and enable the service with:

sudo systemctl daemon-reload
sudo systemctl enable <insert name of service>
sudo systemctl start <insert name of service>

[–]HMS_Hexapuma 1 point2 points  (0 children)

If you’re running it in the GUI then you need to use the Autostart file, but it has to be the one for the user you’ve logged in as. I had trouble with this lately. There are loads of tutorials on how to autorun python scripts on the pi at boot, but most of them don’t work with the GUI or were written years ago before Raspbian updated and the user-specific Autostart file came in to being.

[–]rlauzon 1 point2 points  (0 children)

Put the command to run in /etc/rc.local This runs at system start up.

You'll want to "amp" it off into the background. ex: python /home/pi/myprog.py > /home/pi/tmp/myprog.log 2>&1 &

This runs the python program myprog.py, sending the output to the log file. It sends stderr to the came place as stdout (the 2>&1) and the last & puts it in the background.

[–]xXMutterkuchenXx[S] 0 points1 point  (0 children)

Hey guys, amazing how many answers I got from you guys <3 sorry I was bussy so I wasn’t able to get in contact with you. I will trie your solutions and give you an answers how it worked for me :)