rphvw
Posts: 6
Joined: Thu Sep 16, 2021 8:37 pm

Trouble to start application at reboot

Thu Sep 16, 2021 9:03 pm

Hi,

As a beginner with raspberry pi I bought the great raspberry pi model 3B. Installed Python 3.9.7. Installed espeak. Running /home/pi/sample.py does the audio jack play "Welcome to the world of robots". Crontab is extended with: @reboot sudo python /home/pi/sample.py. At reboot no sound is heard. I only succeeded with Crontab to execute a Python script by using 'launcher.sh' which creates a file but did not do anything more sound actions in that python file. I extended the crontab line creating a log file. The resulting logfile is created but it's size is zero bytes. To be short: I tried many examples from the Internet, also using local.rc. simply said (frustrating): none of them works. I think I severely do miss something very important to know but don't know what... Maybe you can help me out. Thanks in advance.
Henk

klricks
Posts: 8037
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Trouble to start application at reboot

Fri Sep 17, 2021 7:23 pm

If your script requires desktop then use autostart.
See autostart details here: viewtopic.php?f=66&t=294014
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

User avatar
thagrol
Posts: 5848
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Trouble to start application at reboot

Fri Sep 17, 2021 10:00 pm

And here for other methods: viewtopic.php?f=91&t=314455
I'm a volunteer. Take me for granted or abuse my support and I will walk away

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
thagrol
Posts: 5848
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Trouble to start application at reboot

Fri Sep 17, 2021 10:04 pm

rphvw wrote:
Thu Sep 16, 2021 9:03 pm
Crontab is extended with: @reboot sudo python /home/pi/sample.py. At reboot no sound is heard. I only succeeded with Crontab to execute a Python script by using 'launcher.sh' which creates a file but did not do anything more sound actions in that python file.
Desktop or lite? Desktop is now using pulse audio which is only available after login. @reboot cron jobs run before login and do not know which potential desktop to connect to.
I extended the crontab line creating a log file. The resulting logfile is created but it's size is zero bytes.
What did you extend it to, and did you capture stderr as well as stdout?

For example:

Code: Select all

@reboot /home/pi/myscript.py > /home/pi/myscript.log 2>&1
I'm a volunteer. Take me for granted or abuse my support and I will walk away

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

rphvw
Posts: 6
Joined: Thu Sep 16, 2021 8:37 pm

Re: Trouble to start application at reboot

Wed Sep 22, 2021 5:15 am

Hi,

#open de desktop startfile:
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
#add application start code
@/usr/bin/python3 /home/pi/myApp.py

#and it works!

thanks all!

Return to “Beginners”