I'm creating a time-lapse camera to attach to a pair of glasses.
I tried out my script (python 3) and it works, but I need to get my script to work upon startup up since it will powered by a powerbank and I can't manually start the script because of that. (filename is "GlassCam.py" in the folder named "GlassCam")
This is what I've tried in the command line:
sudo nano ~/.config/lxsession/LXDE-pi/autostart
then in the menu
sudo /usr/bin/python3 /home/pi/GlassCam/GlassCam.py
(control+x and then y to save)
yet it won't start when I reboot it or shut it down and plug it back in
1 Answer 1
For starting programs on boot you should make a systemd unit. I do not have enough information of detailed dependencies from your python script but as template for your needs I suggest to start with:
rpi ~$ sudo systemctl --force --full edit glasscam.service
In the editor insert these statements, save it and quit the editor:
[Unit]
Description=startup GlassCam
After=graphical.target
Wants=graphical.target
[Service]
Type=simple
ExecStart=/usr/bin/python3 /home/pi/GlassCam/GlassCam.py
[Install]
WantedBy=graphical.target
Check with systemctl cat glasscam.service
and systemctl status glasscam.service
. Enable the new service with:
rpi ~$ sudo systemctl enable glasscam.service
Reboot.
Explore related questions
See similar questions with these tags.
rc.local
file in/etc
. Before theexit
keyword, writepython3 /path/to/script/GlassCam.py