automate applications on raspberry pi

View previous topic View next topic Go down

automate applications on raspberry pi

Post by jamied_uk on 17th February 2014, 16:14

http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/auto-running-programs


Auto running applications in the GUI
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=18968


Auto running terminal applications (non GUI)

First ensure your program is executable by finding it in the file manager.  Right click on the file and select properties.  Select the permissions tab, check the ‘Make the file executable’ box and press OK.  Or from the command line use:
Code:

sudo chmod +x /home/pi/projects/my_project.a
Or using a different tool set its chmod to 755 (rwxr-xr-x).  It doesn't matter if the user is root.
Doesn't work?
We've found that when copying a new file to the rpi using WinSCP, changing its properties to 755 and verifying all is OK that if we kill the power and power up again the executable doesn't run.  However if we use sudo reboot at the command line it works as it should.  It seems there is some sort of caching action going on so after doing this use sudo reboot the first time rather than cycling the power!
You can setup the auto run using a script (see here), or you can do it directly by editing the rc.local file:
Code:

sudo nano /etc/rc.local
 
After the initial comments (lines beginning with '#') add the following lines:
Code:

# Auto run our application
sudo /home/pi/projects/my_project.a &
"sudo" assumes you want your application run with root user privileges (remove if not) and the "&" says do it in the background.
Save it by pressing Ctrl+X, " Y", ENTER
Re-boot your RPi and it will run.
To kill the program

If you need to kill your program running in the background you can use this
Code:

sudo killall my_project.a
 
Running multiple things and also programs as a non root user

You can use brackets around multiple commands each separated by a ';' followed by the '&' to run the set of commands all in the background.
If you use the '&' you can also run multiple lines as each is run in the background.
Finally, by default rc.local runs as the root user.  You can change to a different user using su - USERNAME -c before the command and surrounding it with quotes.
In the example below the following occurs:
After a 2 second pause my_project.a us run in the background.
After a 5 second delay VLC is started to stream the raspberry pi video camera.  VLC won't run as the root user so su -c is used to make it run as the user "pi"
Code:

#Auto run our application
(sleep 2;sudo /home/pi/projects/my_project/my_project.a)&
#Auto run VLC video streaming
(sleep 5;su - pi -c "raspivid -o - -t 0 -n -w 640 -h 480 -fps 15 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264")&
avatar
jamied_uk
Admin

Posts : 2280
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum