basvs
Posts: 3
Joined: Sat Apr 28, 2018 4:03 pm

Run (Camera) Script on bootup

Sat Apr 28, 2018 5:00 pm

Hi all,

I'm trying to build an interactive system which sends video to a browser accessible to all inhabitants in a home-environment. Using the Raspberry Pi Zero (headless), I followed this tutorial (https://desertbot.io/blog/how-to-stream-the-picamera) and it all works fine now.

However, since I'll be placing my system in some else's house for a week long deployment test, I'm trying to get the raspberry start sending video automatically once booted up. I pretty sure this must be possible, however I wasted the whole afternoon with failed attempts, so some help would be welcome :)

Basically, the Raspberry needs to execute the following commands automatically after WiFi has been initiated and I'll be set (hopefully):

Code: Select all

cd /home/pi/projects/mjpg-streamer/mjpg-streamer-experimental/
./mjpg_streamer -o "output_http.so -w ./www" -i "input_raspicam.so"
Anyone knows how to get this done?

All the best,
Bas

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

Re: Run (Camera) Script on bootup

Sun Apr 29, 2018 1:11 pm

Hi.

One way to do this would be to use cron and the command @reboot

Now as you want to be sure your pi is connected to wifi I would add a delay to give the pi a change to make the wifi connection.

so at the command line

Code: Select all

crontab -e
if you have not used cron before just accept the default editor which is nano.

one the file opens scroll to the bottom of the file and add this line

Code: Select all

@reboot sleep 60 && /home/pi/projects/mjpg-streamer/mjpg-streamer-experimental/mjpg_streamer -o "output_http.so -w ./www" -i "input_raspicam.so"

you should also make sure there is a blank line after this line.

then do Ctrl & o to write the file
and Ctrl & x to exit
if all is well you should get a message installing new cron.

now when you boot or reboot your pi will wait 60 seconds and then start mjpg with your options.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

basvs
Posts: 3
Joined: Sat Apr 28, 2018 4:03 pm

Re: Run (Camera) Script on bootup

Mon Apr 30, 2018 5:59 pm

Hi!,

thanks, it seems like this is what I'm looking for, however, it does not work yet :(

I find it super weird, because whenever I'm executing the following lines from my Mac terminal to Rasperry Pi, it works;

Code: Select all

export LD_LIBRARY_PATH=/home/pi/projects/mjpg-streamer/mjpg-streamer-experimental/
cd /home/pi/projects/mjpg-streamer/mjpg-streamer-experimental/
mjpg_streamer -o "output_http.so -w ./www" -i "input_raspicam.so"
but as soon as I put the two last lines together (see below), I get a 404 error on the webserver:

Code: Select all

export LD_LIBRARY_PATH=/home/pi/projects/mjpg-streamer/mjpg-streamer-experimental/
/home/pi/projects/mjpg-streamer/mjpg-streamer-experimental/mjpg_streamer -o "output_http.so -w ./www" -i "input_raspicam.so"
my crontab now looks like this, but whatever I change, it does not even seem to start the server...

Code: Select all

@reboot sleep 60 && export LD_LIBRARY_PATH=/home/pi/projects/mjpg-streamer/mjpg-streamer-experimental/
cd /home/pi/projects/mjpg-streamer/mjpg-streamer-experimental
mjpg_streamer -o "output_http.so -w ./www" -i "input_raspicam.so"
Any idea what this could cause? Thanks in advance :)

Best,
Bas

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

Re: Run (Camera) Script on bootup

Mon Apr 30, 2018 6:48 pm

possibly need
+ 2 more " && "
and
- 2 less " enter "

so try

Code: Select all

@reboot sleep 60 && export LD_LIBRARY_PATH=/home/pi/projects/mjpg-streamer/mjpg-streamer-experimental/ && cd /home/pi/projects/mjpg-streamer/mjpg-streamer-experimental && mjpg_streamer -o "output_http.so -w ./www" -i "input_raspicam.so"
but how about style? try a script from there:
nano mystart

Code: Select all

#!/bin/sh
sleep 60
export LD_LIBRARY_PATH=/home/pi/projects/mjpg-streamer/mjpg-streamer-experimental/
cd /home/pi/projects/mjpg-streamer/mjpg-streamer-experimental
mjpg_streamer -o "output_http.so -w ./www" -i "input_raspicam.so"
chmod +x mystart

crontab -e

Code: Select all

@reboot /home/pi/projects/mjpg-streamer/mjpg-streamer-experimental/mystart
( not tested )

basvs
Posts: 3
Joined: Sat Apr 28, 2018 4:03 pm

Re: Run (Camera) Script on bootup

Tue May 01, 2018 6:50 pm

You're the boss! This works.

Thanks a lot! :D

Return to “Beginners”