ilovehd
Posts: 8
Joined: Fri Nov 15, 2013 7:29 pm

How to delay the start of a program

Mon Mar 05, 2018 8:59 pm

I have a PI model 3 B running Jessie that auto starts chromium and loads a webpage using:

this file is located at: /home/pi/.config/autostart/autoChromium.desktop

[Desktop Entry]
Type=Application
Exec=/usr/bin/chromium-browser --incognito --noerrdialogs --kiosk http://websiteaddress.com
X-GNOME-Autostart-enabled=true
Name[en_US]=AutoChromium
Name=AutoChromium
Comment5=Start Chromium when GNOME Starts


That works great! My issue is that sometimes this launches before wifi has connected and therefore gives a page cannot be displayed error. Is there any way to add a delay into the above so the wifi has a chance to connect before the browser loads? I've tried just adding sleep 20 above the Exec command but that causes it to not load at all..

Thanks!

pcmanbob
Posts: 9612
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: How to delay the start of a program

Tue Mar 06, 2018 12:00 am

Have you tried enabling wait for network at boot under boot options in raspi-config
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

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

Re: How to delay the start of a program

Tue Mar 06, 2018 12:45 am

Something like this has worked for me:

Make a bash script file for example my_file

Code: Select all

nano /home/pi/my_file

Code: Select all

sleep 3
chromium-browser --incognito --noerrdialogs --kiosk http://websiteaddress.com
Add this line to autostart:

Code: Select all

@bash /home/pi/my_file &
Adjust sleep time if necessary.

I don't know if this will work using the exec= line in the desktop file????? I have never tried that method.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: How to delay the start of a program

Tue Mar 06, 2018 1:24 am

this seems to work too

nano /home/pi/.config/autostart/myautostart.sh

Code: Select all

#!/bin/bash
# /home/pi/.config/autostart/myautostart.sh
# this will not do anything unless called by a .desktop file

echo '10s'
env sleep 5
echo '5s'
env sleep 5
#...


/usr/bin/chromium-browser --incognito --noerrdialogs --kiosk http:///www.raspberrypi.org/forums/

# wait for operator to close window ( only for first test / not visible if browser starts )
read -p "press enter to close terminal window"
possibly there is a way to ask for the ready internet connection?


nano /home/pi/.config/autostart/myautostart.desktop

Code: Select all

[Desktop Entry]
Type=Application
Name=browser kiosk
Exec=lxterminal -e /home/pi/.config/autostart/myautostart.sh
Icon=leafpad
Comment=start browser after time delay
Terminal=true
X-KeepTerminal=false
Categories=Network;

ilovehd
Posts: 8
Joined: Fri Nov 15, 2013 7:29 pm

Re: How to delay the start of a program

Tue Mar 06, 2018 11:52 am

pcmanbob wrote:
Tue Mar 06, 2018 12:00 am
Have you tried enabling wait for network at boot under boot options in raspi-config
This seems to work. I totally missed this in the config, Thank you!

Now the next question do you know how to turn this option on from the command line? I have a few of these that I would like to SSH into and turn this on.

Thanks!

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

Re: How to delay the start of a program

Tue Mar 06, 2018 1:17 pm

ilovehd wrote:
Tue Mar 06, 2018 11:52 am
pcmanbob wrote:
Tue Mar 06, 2018 12:00 am
Have you tried enabling wait for network at boot under boot options in raspi-config
This seems to work. I totally missed this in the config, Thank you!

Now the next question do you know how to turn this option on from the command line? I have a few of these that I would like to SSH into and turn this on.

Thanks!
sudo raspi-config
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

n67
Posts: 938
Joined: Mon Oct 30, 2017 4:55 pm

Re: How to delay the start of a program

Tue Mar 06, 2018 1:47 pm

Comments:

1) I usually do this sort of thing in code, rather than rely on frequently changing obscure raspi-config options. And anything based on hard coded delays (sleep XXX) will, eventually fail because the wait wasn't long enough OR because the wait was too long and the user thinks that nothing is happening (i.e., the machine is "hung"). To do it right, you need to actually check the thing you are waiting for. In this case, the most straightforward way is to check if pinging a known host works. Something like:

Code: Select all

until ping -4 -c1 google.com 2> /dev/null 
do sleep 2
done
Note: If you know it, you could use your router's IP (or, for that matter, any other host on your LAN) rather than google - to avoid putting traffic on the global Internet.

2) If you still want to use raspi-config, and don't want to do the steps interactively, then you will need to dig into the raspi-config code (which, luckily, is a shell script, so it is readable/hackable) and figure out what it does to wait for the network. Good luck and have fun!
"L'enfer, c'est les autres"

G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:

Epmu Sn!

J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!

ilovehd
Posts: 8
Joined: Fri Nov 15, 2013 7:29 pm

Re: How to delay the start of a program

Tue Mar 06, 2018 1:56 pm

klricks wrote:
Tue Mar 06, 2018 1:17 pm
ilovehd wrote:
Tue Mar 06, 2018 11:52 am
pcmanbob wrote:
Tue Mar 06, 2018 12:00 am
Have you tried enabling wait for network at boot under boot options in raspi-config
This seems to work. I totally missed this in the config, Thank you!

Now the next question do you know how to turn this option on from the command line? I have a few of these that I would like to SSH into and turn this on.

Thanks!
sudo raspi-config

Thanks!

Return to “Beginners”