0

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

  • look through the 10 posts just before your post ... one of them may have what you need – jsotola Jun 12 '18 at 6:17
  • put your script in rc.local file in /etc. Before the exit keyword, write python3 /path/to/script/GlassCam.py – bierschi Jun 12 '18 at 7:54
  • rc.local from old style SysVInit is only emulated by systemd and becomes more and more deprecated. There are some feedback here on this site that it no longer work as expected. You should really use a systemd unit to start programs. – Ingo Jun 12 '18 at 8:51
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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.