You are on page 1of 29

rbnrpi

This WordPress.com site contains thoughts on using my Raspberry Pi

Setting up Wireless motion-detect cam UPDATED

ARTICLE UPDATE

I have received many requests for help with this project since I first wrote it over a year ago. So I decided to take another look at it. As it said at the beginning of the original article, the main input came from a posting by dozencrows, in
the RaspberryPi Forums. He has in fact done further work on the original article, and a much better implementation can be downloaded from this post here. The actual download link for the modified motion file and associated config file is
here. I have tried this out today on the very latest raspbian distro. As in the original article you should install motion and libjpeg62. Then download dozencrows modified motion and config file. For safety I suggest renaming HIS version of
the motion file motion-mmal and using the set up and run command from my original article. That way you dont run the installed motion binary by mistake.

./motion-mmal -n -c motion-mmalcam.conf

I tried this with his config file as downloaded, but you can of course modify it to meet your own requirements.

I also checked this out with my Synology NAS running DSM 5 with surveillance station 6.3

Set up the camera as per the picture in the original article, and you can then record using that program. I hope that this update will make it easier for readers to get this going.
The original article follows below.

This project is based on a post by dozencrows here which explored the use of a Raspberry Pi camera board as a motion detecting video cam. It is based on the motion package in Debian. He has recompiled this with a slightly different
configuration, making it convenient to work with the Raspberry Pi cam board. I take no credit for the code, but hope that details of how I have se it up on my system, and how I have connected it to a Synology NAS with built in
Surveillance Station will be of interest to others. The original thread has multiple posts on it, and it can be confusing to get to grips with the code as a result.

What you need:

A Raspberry Pi, with PSU, camera board and WiFi adaptor (It would work with an ethernet connection, but it makes it less convenient for placing the camera is a suitable location. An SD card containing an uptodate copy of the wheezy-
raspian distribution. If you have a blank card you can put the distribution on it together with configuring the wifi dongle by following the first section of my article here. You should also remember to check that the camera code support is
enabled by typing sudo raspi-config and setting option 5
For convenience I have ssh enabled on my card so that I can carry out the work on it via a link to a terminal on my main computer.

My wireless lan port has ip address 192.168.1.98, so I connect to the pi using


Follow
ssh pi@192.168.1.98 from a terminal window on my mac (you can install and use putty on Windows)
Follow rbnrpi
Now to get going: Get every new post delivered
to your Inbox.
First make sure (if you havent already) that your raspian is up to date. Join 40 other followers
type
sudo apt-get update Enter your email address
sudo apt-get upgrade
it is also a good idea to make sure your firmware is up to date
Sign me up
sudo apt-get install rpi-update
and run it sudo rpi-update Build a website with WordPress.com

a reboot is required when this is finished


sudo shutdown -r now
(you will have to reconnect via ssh when the Rpi has restarted if you are using a remote terminal)

Now install the motion program


sudo apt-get install motion

We dont actually use this version, but it does insure that all the necessary dependencies are installed as well

sudo apt-get install libjpeg62

create and enter a directory called mmal in the user pi home directory using
cd ~/
mkdir mmal
cd mmal
download dozencrows version of the motion program using
wget https://www.dropbox.com/s/xdfcxm5hu71s97d/motion-mmal.tar.gz
and extract the contents with
tar -zxvf motion-mmal.tar.gz
you now modify the configuration file, by opening it with the editor nano
nano motion-mmalcam.conf
nano hints
To insert a blank line, move to the beginning of a line and press return
To delete a line position the cursor on the line and press ctrl+k
use the backspace arrow to delete characters
you can search for a string by typing ctrl+w and inserting the string you wish to find.
When you have finished amending the file use ctrl+o to write out the amended file, selecting the existing filename to overwrite by pressing return. Then select ctrl+x to exit the editor.

you are going to alter the lines for


width
height
target_dir
output_pictures
text _left
logfile
search for them in turn using ctrl+w and set them as follows

width 640
height 480
target_dir /home/pi/m-video
output_pictures off
text_left Pi-cam %t
logfile /home/pi/mmal/motion.log

then write the changes out using ctrl+o push return and exit the editor with ctrl+x

So that there is no confusion as to which motion binary is running I rename the one in the mmal directory using mv motion motion-mmal

Assuming your camera board is correctly installed, you are now in a position to test it out
In your terminal window, from the mmal directory type
./motion-mmal -n -c motion-mmalcam.conf
where upon the camera board red led should light, and if you start a browser on another computer on your local network (Internet Explorer doesnt work but Chrome, Firefox and Safari are ok) you should see live pictures at
http://192.168.1.98:8081
You quit the process by typing ctrl+c

The start stop process is hardly ideal, so I have written a couple of scripts to start and stop the process.

type nano startmotion


In the editor window type
#!/bin/sh
nohup ~/mmal/motion-mmal -n -c motion-mmalcam.conf 1>/dev/null 2>&1 </dev/null &

type ctrl+o then push the return key to write the text, followed by ctrl+x to exit the editor
chmod 755 startmotion to make it executable

type nano stopmotion


In the editor window type

#!/bin/sh
ps -ef | grep motion-mmal | awk '{print $2}' | xargs kill

note: I put the script above in a code block as wordpress changes the quotes to smart ones otherwise which dont work if you copy and paste

type ctrl+o then push the return key to write the text, followed by ctrl+x to exit the editor
chmod 755 stopmotion to make it executable

now you can type ./startmotion to start the camera and ./stopmotion to stop it
The videos created are stored in the m-video in the mmal home directory and the process is logged in the motion.log file
The command used in the start motion script was suggested by adayforgotten in the original topic thread. As you have seen, if you type the ./motion-mmal command to start the camera directly you cannot type subsequent commands
into the terminal, and if you type ctrl+c or exit the terminal then the process terminates. Wrapping the command in nohup& makes it run in the background and be independent of the terminal closing, which would normally stop
dependent processes The >/dev/null redirects the standard output to /dev/null, throwing it away. The 2>&1 part redirects the standard error output of the command to the standard output. the </dev/null unattaches the console
keyboard and uses </dev/null instead. Thus the script can start the process without producing any screen output.
The stopmotion script uses ps-ef to give a formatted list the process id of running processes, pipes the output to grep to find the line for the process motion-mmal pipes that to awk {print $2} which extracts the second field or process
ID and finally pipes to xargs which feeds in turn any matching ID to kill which terminates them. It is instructive to build up this command line manually trying each step in turn. Thus
ps -ef
ps -ef |grep motion-mmal
ps -ef | grep motion-mmal | awk {print $2}
etc to see the output of each stage in turn (you should have the process running first of course!)

Connecting the the Synology NAS surveillance module


If you have such a NAS you can log in to it with a web browser and start the supplied surveillance station. The trick is in how to setup the camera configuration.
The photo below shows the settings which have to be entered

Although the frame rate is rather slow, the system works and in the time line of the Surveillance program you can inspect video where there has been motion detected.
The surveillance program has a full help file.

Quck install files


I have put the start and stop scripts plus my amended motion-mmalcam.conf file in a zip file which you can download here into your Pi home directory using

wget http://r.newman.ch/mmal-bits.zip
followed by unzip mmal-bits.zip
quick install instructions are included in a README file

SH A R E TH I S :

Twitter Facebook 1 Google

Like
4 bloggers like this.

83 THOUGHTS ON SETTING UP WIRELESS MOTION-DETECT CAM UPDATED


J Beale (@JBeale3)
on July 27, 2013 at 12:21 am said:

Very handy writeup, thank you! I set my configuration to 640480 resolution and 3 fps. That works, and the AVI generated by motion-mmal as you
describe can be played by VirtualDub 1.9.11 on Windows XP, but it always gives me the following warnings:

[!] AVI: Index not found or damaged reconstructing via file scan.
[!] AVI: Keyframe flag reconstruction was not specified in open options and
the video stream is not a known keyframe-only type. Seeking in the video
stream may be extremely slow.

koufs
on July 27, 2013 at 4:25 pm said:

Thanks for this tutorial. Its been a huge help.

However, I had issues with the stopmotion script. Is there any reason why one cant simply use:

#!/bin/sh
killall motion-mmal

It seems to work well for me.

rbn2013
on July 27, 2013 at 9:05 pm said:

Sorry there was a typo in the script which Ive now corrected
Yes I think your version is simpler!

Rui Marinho
on July 27, 2013 at 4:27 pm said:

Clean and simple :)


Just had to make a fix in the stopmotion file is missing a bracket ?
ps -ef | grep motion-mmal | awk {print $2} | xargs kill
rbn2013
on July 27, 2013 at 9:00 pm said:

Oops sorry typo which Ive now corrected. It is correct in the zip file I think

Francisco
on August 4, 2013 at 9:17 pm said:

Thank you very much for this fantastic approach.


I have a problem with the movies which are stored in /home/pi/m-video/.
Is it possible to deactivate this feature and that only the streaming-function is working? Is there a parameter in motion-mmalcam.conf which can disable
saving movies?

rbn2013
on August 5, 2013 at 10:06 pm said:

Ill try and check for you. I think there may be something on this on the thread on MMAL on the Raspberry Pi Forum. Even if you cant stop them,
you could add a script to delete the oldest if space is an issue.

adam
on January 4, 2015 at 8:32 pm said:

line reading ffmpeg_output_movies on changed to off will result in no output of movies

Mike
on August 18, 2013 at 9:30 pm said:

Is there a restriction on the 640480 size here? The pi cam can do full HD.

Im experiencing some stability issues with motion (with USB camera) but can get 720p quality currently May be I should reduce to this lower resolution
too.
rbn2013
on August 21, 2013 at 8:05 am said:

Hi Mike
The originator of the MMAL thread on raspberrypi.org

dozencrows wrote:
A note on image resolution

Currently, only certain resolutions work. My personal testing has shown the following work:

352288
640480
1024576

Hope this helps

Andy
on September 9, 2013 at 3:39 pm said:

Thanks for the tutorial, it works really well, except it doesnt use my raspberry pi camera board, instead it uses my usb camera. Is there a way I can select
to use the camera board instead?

John
on September 26, 2013 at 11:40 am said:

Hi
Thanks for the tutorial. I was having a bit of trouble setting this up before but starting from scratch using your tutorial has made it easier.
FYI It looks like (so far at any rate) setting ffmpeg_output_movies to off in motion-mmalcam.conf will stop generation of avi files in the m-video directory.

maco1717marco
on October 31, 2013 at 2:46 pm said:
Hi, ive been having loads of problems recently with motion, i managed to set it up with a webcam a while back and have it working, but last monday
started again with this project and nothing is working, webcam doesnt stream I had several model of webcam and the board cam which is why im here
trying with this as i tought it might be better to troubleshoot with this. it is generating videos on m-video folder but its not streaming, when i go IP:8081
what could I try to find out whats going wrong?

thanks.

rbn2013
on October 31, 2013 at 3:52 pm said:

Im a bit rusty with this, not having played with it either since I wrote the blog. Ill see if I can dig it out and have a go again. However, I think it is an
ongoing project, so the original author may well have updated the software since I wrote this article. May be worth checking the camera forum in
raspberrypi.org at
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=43&t=44966&hilit=MMAL+camera+stream

JohnZajla
on November 3, 2013 at 4:48 pm said:

By me the ./stopmotion command dont workthe error: awk: 1: unexpected character 0xe2
Then i see in nano the quotes are not right. When you copy/paste from wordpress to nano is not the same.

WordPress seems to be messing up the single and double quotes, you need to remove them and retype them in.

rbn2013
on November 4, 2013 at 1:37 pm said:

Well it does say type in the article not copy and paste. I didnt put it in a code block where it would have copied ok.
There is always the option of using the download for the files.
Ill see if I can alter it so it will copy and paste ok.

rbn2013
on November 4, 2013 at 2:04 pm said:

put this script in a code block so you CAN copy and paste it ok. Previously wordpress altered the quotes to smart ones which dont work.
Thanks for the comment John
Andreas
on November 9, 2013 at 11:18 pm said:

Wonderful manual (in particular if I compare it to the almost stupid stuff that is copy-and-pasted elsewhere). Still, I get a problem. My log says

[-1242889376] [NTC] [ALL] [Nov 09 22:14:28] motion_startup: Using log type (ALL) log level (WRN)
[1] [ALR] [VID] [Nov 09 22:14:28] mmalcam_start: MMAL Camera thread starting for camera (vc.ril.camera) of 1024 x 576 at 2 fps
[1] [ALR] [VID] [Nov 09 22:14:28] mmalcam_start: MMAL Camera using video capture
[0] [ERR] [ALL] [Nov 09 22:14:58] main: Thread 1 Watchdog timeout, trying to do a graceful restart
[0] [ERR] [ALL] [Nov 09 22:15:10] main: Thread 1 Watchdog timeout, did NOT restart graceful,killing it!
[0] [ERR] [ALL] [Nov 09 22:15:58] main: Thread 1 Watchdog timeout, did NOT restart graceful,killing it!
[0] [ALR] [VID] [Nov 09 22:15:58] MMAL Camera cleanup
[1] [ALR] [VID] [Nov 09 22:15:59] mmalcam_start: MMAL Camera thread starting for camera (vc.ril.camera) of 1024 x 576 at 2 fps
[1] [ALR] [VID] [Nov 09 22:15:59] mmalcam_start: MMAL Camera using video capture
[0] [ERR] [ALL] [Nov 09 22:16:28] main: Thread 1 Watchdog timeout, trying to do a graceful restart

Any idea what is going on here?

rbn2013
on November 12, 2013 at 5:42 pm said:

Its a few months since I played with this, and unfortunately I cant get at my camera and Pi at present as my workroom is being decorated!
Is your cam working when you start things going? Red light should be on and pic on local screen.
Look at the Rasberry Pi thread on http://www.raspberrypi.org/phpBB3/viewtopic.php?f=43&t=44966

Thats where I got most of my info on this project from

TWdetective
on November 12, 2013 at 8:24 am said:

Thats great help!

Sheepkob
on November 16, 2013 at 9:42 am said:

Hi! Thank you a lot for this very simple tutorial. Its so simple that I cant get motion working

I dont use yet the scripts to start and stop the stream. So I type this :
./motion-mmal -n -c motion-mmalcam.conf

And it stay stuck here :


[-1242705056] [NTC] [ALL] conf_load: Processing thread 0 config file motion-mmalcam.conf
[-1242705056] [NTC] [ALL] motion_startup: Motion mmaltest Started
[-1242705056] [NTC] [ALL] motion_startup: Logging to file (/home/pi/MMAL/motion.log)

Safari cant access to the server when typing http://(RPIaddress):8081

The motion-mmalcam is very close to yours.

Did I missed something?

Here is the result of raspistill -v -o temp.jpg :

raspistill Camera App v1.3.5

Width 2592, Height 1944, quality 85, filename temp.jpg


Time delay 5000, Raw no
Thumbnail enabled Yes, width 64, height 48, quality 35
Link to latest frame enabled no
Full resolution preview No
Capture method : Single capture

Preview Yes, Full screen Yes


Preview window 0,0,1024,768
Opacity 255
Sharpness 0, Contrast 0, Brightness 50
Saturation 0, ISO 0, Video Stabilisation No, Exposure compensation 0
Exposure Mode auto, AWB Mode auto, Image Effect none
Metering Mode average, Colour Effect Enabled No with U = 128, V = 128
Rotation 0, hflip No, vflip No
ROI x 0.000000, y 0.000000, w 1.000000 h 1.000000

Thank you for your help.

rbn2013
on November 16, 2013 at 3:04 pm said:
on November 16, 2013 at 3:04 pm said:

It is several months now since I was playing with this, so I am a bit rusty on the topic. I will try and dig out my camera and have a look again at it
during the next week.

Andreas
on November 16, 2013 at 9:25 pm said:

Have you tried Firefox? My safari wont show the stream but firefox does.

Sheepkob
on November 19, 2013 at 9:24 pm said:

Unfortunately, its the same. It seems the Raspberry doesnt stream anything

Don DeGregori
on November 21, 2013 at 1:23 am said:

This tutorial is the best so far, short and understandable. One question. If I error and send
./startmotion again after motion is already running, ./stopmotion will not work. I tried a several times to stop, but could not. Had to do shutdown.

keith johnson
on December 1, 2013 at 3:40 am said:

try using vlc when opening the streams. browsers have issues.

Kamlesh
on December 14, 2013 at 10:46 am said:
when I try to build motion with config file I get error

ioctl (VIDEOCGCAP): Invalid argument in motion

Can you please help me figure what am I doing wrong ?

rbn2013
on December 14, 2013 at 3:10 pm said:

Not sure you should be trying to build motionThis article is written around a cuastomised downloadable binary. However, you should follow the
renaming I describe to make sure you are using the correct binary, as you also install the standard motion to get the supporting files. The config file
will only work with the customised motion binary that you download as described.

citizenbrianbrian
on January 8, 2014 at 1:33 pm said:

Installed, start and stop files work but I havent got in the stream on Google+ Safari, VNC viewer or RDP, After a few minutes of it running it knocked out
my lan connection so I couldnt connect even with Putty which I had running at the time, the camera light is still on and the single red power light on the
board. I pulled out my cat5 and reinserted but it didnt re-connect so I pulled the power and rebooted, now going for a re-run, booted ok cd mmal
./startmotion and its running again. Rfb protocol error on VNC, im now trying VLC via loads of reading on Google.

ravensquire101
on January 11, 2014 at 4:47 pm said:

Hello, thanks for the tutorial it worked first time :-)

Is there any chance you would know how to get the PI to automatically start motion on boot. This would help for power outages and reboots etc

rbn2013
on January 11, 2014 at 6:26 pm said:

Something like this should do it. http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/auto-running-programs

ravensquire101
on January 16, 2014 at 3:21 pm said:
on January 16, 2014 at 3:21 pm said:

Hello RBN2013,
Unfortunately it doesnt appear to be so easy. I have added
(sleep10;su pi -c/home/pi/mmal/startmotion)&
to my rc.local and when I log in and top motion-mmal is running however there is no light on the camera board and no webpage display
ing the output. If I then ./stopmotion and ./startmotion everything works.

I note that the startup text says


[warn] Not starting motion daemon, disabled via /etc/default/motion /// (warning)
However I believe this is generated by the motion package and not MMAL motion package. If I edit this file to say yes plain old motion
starts.

Do I need to add the user system to any groups or anything like that and if so how?

Thanks
Steve

rbn2013
on January 16, 2014 at 5:23 pm said:

It looks as if the mmal package is not starting. You shouldnt have to change any groups. I changed the name of the modified package to
motion-mmal and the conf file specifically to avoid confusion between the installed motion package and the modified version and used
./motion-mmal -n -c motion-mmalcam.conf to start things. It looks as if the correct one is not starting.

ravensquire101
on January 17, 2014 at 10:22 am said:

Thanks rbn2013,
I did as you suggested and used ./motion-mmal -n -c motion-mmalcam.conf in my rc.local This piped the error messages to the com
mand prompt (making it unusable so I had to SSH in, but it was very good feedback for debugging).

I am not sure if it was a problem but I discovered that I had Start in Deamon as on in both the mmal conf file and the standard one (I
turned them back off).

Furthermore I discovered that I had to give the explicit location of the conf file in the RC.Local and not just the file name. If motion can not
oped the specified conf file it will use the default one.
So if you dont tinker with anything you should just be able to add the following line to the RC.local for it to start automatically.
(sleep 4;su pi -c /home/pi/mmal/motion-mmal -n -c /home/pi/mmal/motion-mmalcam.conf)&

Thanks again

citizenbrianbrian
on January 11, 2014 at 10:59 pm said:

At this moment in time the motion program is running ;-)

roysr2d2
on January 20, 2014 at 9:09 am said:

Thanks for the clear explanation of how to set this up. I have it all working however it is very slow with about a ten second delay between the actual motion
and that being streamed. Any idea how I could fix this?

rbn2013
on January 21, 2014 at 1:01 pm said:

Not sure that it is possible to eliminate the delay with this setup.

Dave
on February 26, 2014 at 6:26 am said:

Hi,
I tried this and was able to finally get motion up and working and that was great. But after a few image captures by motion detection the images cease to
be captured. . maybe a few minutes and no more images or videos are saved. There is plenty of disk space, the motion process is still running and the
people pi noir cam LED continues to remain lit. I dont want to introduce another process to restart motion. Can you offer any advice?

rbn2013
on February 26, 2014 at 8:51 am said:
on February 26, 2014 at 8:51 am said:

Hi there

I wrote this project last July so Im afraid I am a bit rusty about it now. I suggest you ask the question on the original Raspberry Pi forum article
linked at the beginning of the article.

Miron
on March 1, 2014 at 4:05 pm said:

Hi, this app detects motion as a picture change. So if it is dark and someone enters the camera field he/she wont be detected. There is no real intruder
detection. So it is completely useless as a security camera since burglars wouldnt normally switch on the light when they break in. Would be nice to add
the capability of using a GPIO input as another triggering method using a real infrared intruder detector.

vegoil_bear
on March 1, 2014 at 5:40 pm said:

Hi,

This worked really well. Thanks for the guidance.


Everything I have read about motion suggests it has lots of capabilities even control of PTZ cameras. However, Id like to connect the Pi into an alarm
system so that when motion is detected one of the GPIO lines is toggled but I dont know where to begin with this.

Paul

SageDesign
on March 20, 2014 at 3:39 pm said:

I tried this on 20/1/14, but the .tar file is not available on Dropbox. Is there an alternative, or has it been moved please.

SageDesign
on March 20, 2014 at 3:54 pm said:
on March 20, 2014 at 3:54 pm said:

Please ignore my message I missed a (wee) bit out of the URL sorry.

SageDesign
on March 20, 2014 at 4:18 pm said:

Back again I installed the software and modified the .conf file as specified. The camera red light was already on, having tried to check the view previously
from Firefox, so I re-booted it still on. When I try the program, I get an error message:
mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
Segmentation fault
If you can give me any idea what I have done wrong, I would appreciate it.

rbn2013
on March 20, 2014 at 5:06 pm said:

Im a bit rusty on this Nigel. Havent looked at it for months. Ill see if I have time to check it out again. BTW there have just been advances in the
camera software. Have a look at this. May be of interest. I did some slow mo movies of water drops falling yesterday. Very nice.

Toko Bunga Jakarta


on March 27, 2014 at 8:28 am said:

Thanks for the tips, I will try ASAP.

laurendransfield
on April 22, 2014 at 8:11 pm said:

Hey,

Im having problems with:

tar -zxvf motion-mmal.tar.gz

I get the error:


gzip: stdin: not in gzip format
tar: child returned status 1
tar: Error is not recoverable: exiting now

rbn2013
on April 23, 2014 at 11:27 am said:

Hmm the file appears to be downloading in a not gzip format. I got the same error. It looks like it is still in a html format. What you can do is to
download it on a pc or Mac. Just go to the url there. On a mac you can double click the downloaded gz file and it extracts for you. You could copy
it across to the Rpi using scp. Let me know if you want more help on this.

Gustavo
on May 7, 2014 at 9:15 pm said:

First, thank you very much for this clear tutorial. I got everything working but im having another kind of question. Im kind of new with cameras and the
settings of an camera. Are these settings overruling the default pi camera settings or can i still change the camera settings and these will have influence on
this app? Im having trouble with the images at nighttime, is there an special mode for night?

rbn2013
on May 7, 2014 at 10:57 pm said:

There is an infra red version of the camera available which would be suitable for night time use.

Peter
on May 16, 2014 at 5:16 pm said:

Hi, great tutorial. Motion works ok one thing is missing for me how to make it send email wohen motion is detected. I did setup postfix for that and its
100% working but when I edit on_picture_save (or something like that) line and add %f to attache last taken picture nothing happens any idea for that?
Its raspberry model B and the camera module.

Regards
chloezodiac
on May 23, 2014 at 10:16 am said:

I want to work on a project of security camera. I have a big attachment about security camera.

Mr James
on June 28, 2014 at 10:06 am said:

To monitor each and every motion outside the home using the wireless camera and making he necessary coding for the motion in it for the automatic
motion detection.

martypicco
on June 29, 2014 at 2:14 am said:

Works well. I added a script to the on_picture_save and on_movie_end events that copies the files to Amazon S3 and deletes them from the PI once
theyve been uploaded. It uses s3cmd which is the easily available and well documented s3 command line script.

In the .conf file:

on_picture_save /home/pi/mmal/s2s3.sh
on_movie_end /home/pi/mmal/s2s3.sh

Heres s2s3.sh:

#!/bin/bash

cd /home/pi/motion-capture

var=( $(ls -t) )


name=${var[0]}

dir=`date +%y/%m/%d/%H`

/usr/bin/s3cmd put $name s3://piBucket/$dir/$name

rm $name
TheLuckyOne

on July 10, 2014 at 8:27 am said:

This page was a great help for me. Thank you all for this.

A efficient {start|stop} script to lauch the motion-mmal software automatically when you pi boots is given below. It needs to be placed into /etc/init.d folder.
It assumes that the motion-mmal software and config file are placed in /home/pi/mmal
and that you followed the excellent guidelines at the top of this page:

sudo pico /etc/init.d/motioncontrol

and enter the following code: (starting with #! and ending with the line after exit 0 )

#! /bin/sh
# /etc/init.d/motioncontrol

### BEGIN INIT INFO


# Provides: motioncontrol
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Simple script to start motion-mmal program at boot
# Description: A simple script to start the motion-mmal at boot.
### END INIT INFO

# If you want a command to always run, put it here

# Carry out specific functions when asked to by the system


case $1 in
start)
echo Starting motion-mmal
# run application you want to start
nohup /home/pi/mmal/motion-mmal -n -c /home/pi/mmal/motion-mmalcam.conf 1>/dev/null 2>&1 </dev/null &
;;
stop)
echo "Stopping motion-mmal"
# kill application you want to stop
killall motion-mmal
;;
*)
echo "Usage: /etc/init.d/motioncontrol {start|stop}"
exit 1
;;
esac

exit 0

Save this file, make it executable (chmod u+x /etc/init.d/motioncontrol )


Make it part of the normal startup process:

sudo update-rc.d motioncontrol defaults

Like this the motion-mmal will launch when your pi starts


Starting and stopping can be done using
sudo /etc/init.d/motioncontrol start
sudo /etc/init.d/motioncontrol stop

If you don't want the red LED to light up when motion-mmal is working, add the following line to
/boot/config.txt

sudo pico /boot/config.txt

and add
disable_camera_led=1

at the end of the file. Save and exit. Reboot you pi.

Have fun!

Kampman
on August 30, 2014 at 5:48 pm said:

In case anyone is having trouble using TheLuckyOnes script, check your quotes. The website substitutes different quote characters sometimes
which messes you up when you copy/paste. Script works great by the way. Thanks!

MacP
on September 3, 2014 at 9:26 pm said:

The script is working fine for me as well. Thanks ! Great stuff. Just pay attention when copying the quotes indeed into pico editor. I also struggled
with the (chmod u+x /etc/init.d/motioncontrol). It should be sudo chmod u+x /etc/init.d/motioncontrol. I know Im a rookie. But I learned from it :)
zz2b2
on May 20, 2015 at 5:34 pm said:

Checked scipt for correct text and other characters. But when I start I get unable to execute, no such file or directory

espresso
on July 14, 2014 at 11:38 pm said:

Hello to every body, its my first pay a quick visit of this blog; this web site carries amazing and really
good material for readers.

Jenda Reme
on August 11, 2014 at 5:59 pm said:

Hi,
I have problem, camera make bad movies. Look log:

[-1242782048] [NTC] [ALL] [Aug 11 17:52:26] motion_startup: Using log type (ALL) log level (WRN)
[1] [ALR] [VID] [Aug 11 17:52:26] mmalcam_start: MMAL Camera thread starting for camera (vc.ril.camera) of 640 x 480 at 2 fps
[1] [ALR] [VID] [Aug 11 17:52:26] mmalcam_start: MMAL Camera using video capture
[0] [ERR] [VID] [Aug 11 17:53:14] Received unexpected camera control callback event, 0x0003e220
[0] [ERR] [ALL] [Aug 11 17:53:34] main: Thread 1 Watchdog timeout, trying to do a graceful restart
[0] [ERR] [ALL] [Aug 11 17:54:34] main: Thread 1 Watchdog timeout, did NOT restart graceful,killing it!
[0] [ALR] [VID] [Aug 11 17:54:34] MMAL Camera cleanup

Example movie here: http://jendaremes.cz/domains/jendaremes.cz/pluginfile.php/66/mod_resource/content/1/01-20140811151225.avi

Error 0x0003e220? I dont know, google dont know


I have not any idea for solution this problem :-(
Thank You for feedback.
Jenda

rbn2013
on August 11, 2014 at 6:56 pm said:
on August 11, 2014 at 6:56 pm said:

Im afraid I have not looked at this project since I wrote it over a year ago, and I am not really an expert on this subject! I suggest that you ask in
the raspberry-pi camera board forum
http://www.raspberrypi.org/forums/viewforum.php?f=43 where there are likely to be experts who can give you more help.

MacP
on September 2, 2014 at 8:37 pm said:

Hi rbn2013, Great tutorial on mmal usage and configuration. It really got me started using the RBPI camera module and motion detection. I also have a
synology which I configured according your guidelines. It took me a while to understand connecting the RBPI on the SN theres 2 kind of motion detection.
One done by the motion script on the RBPI and storing AVI files in m-video. The other motion detection is done by the SN surveillance station which has
noting todo with the RBPI motion script. These are 2 different things so it seems.

All is working fine except the timeline recordings. My SN seems to be recording avi files but I cant play them in the SN surveillance station. I get like a little
icon like the file is damaged. When I go to the actual directory on my SN and I download the avi file I have like a 1 frame still video of several seconds. Im
trying to figure out why.

Could you explain in the SN camera config where the /stream.mjpeg is coming from and what its referring to ?

Thanks Peter

rbn2013
on September 3, 2014 at 8:42 am said:

Hi Peter
Glad you enjoyed the article. To be honest it is over a year since I looked at this. I think I got the /stream.mjpeg by experiment, and by looking at
the list of user reported image source path settings in the synology surveillance camera help file, and trying out various combinations. If I have time
I will try and fire things up again, but these days I am heavily into using Sonic-Pi on the RPi (version 2 released yesterday!) as you will see from oth
er entries in my blog.
I wouldnt be surprised if things have changed a bit since I set up the code. New DSM for Synology for a start, and new models for Pi and later
OS, so there may well be bits that need to be tweaked again.

rbn2013
on September 4, 2014 at 10:52 pm said:

Peter. Look at the new update to the article. This works fine with Synology.
Chris

on September 10, 2014 at 5:14 pm said:

Hi rbn2013, nice howto, but how to start it automaticly? I want to start it every time my raspberry starts, im not sure for the right way.
chris

rbn2013
on September 15, 2014 at 3:47 pm said:

Hi Chris
If you Google running a program on raspberry pi automatically on startup you will find articles that will help.

TheLuckyOne
on September 18, 2014 at 8:57 am said:

Look at my comment above from July 10th, 2014. Have fun.

Stephen
on October 8, 2014 at 12:19 am said:

Absolutely fantastic tutorial. It worked perfectly the first time. As a new Pi user, I find projects like this extremely helpful.

Sagar
on November 29, 2014 at 6:46 am said:

Hi,
I have a problem, to access on_movie_end event in motion-mmalcam.conf. on_movie_end is not working on my raspberry PI. The code dosent give me
any error.
I made following changes in motion-mmalcam.conf

. max_movie_time 10
. on_movie_end node sampleNode.js %f

My sampleNode.js code
console.log(on_movie_end trigger fired);

When I execute sampleNode.js from command its give me correct output. I dont understand what wrongs with my changes.

rbn2013
on December 2, 2014 at 10:57 pm said:

Hi
Not sure I can help as it is sooo long since I played with this. Hope you mange to figure it out.

wtree
on December 27, 2014 at 6:33 pm said:

Any ideas why ./startmotion and ./stopmotion isnt working after reboot?
Cheers

cedricverst
on June 1, 2015 at 2:42 pm said:

Instead you can also use Kerberos.io, its also open-source and a lot more user friendly to install and configure. You can find more information on the
website.

Paul
on July 29, 2015 at 5:26 pm said:

Where does the video go if port is set to 0?


I have a server on port 80 with a button to press and have the camera set to 8081 using a videostream.cgi.

html,body {
margin:0px;
padding:0px;

background:#263238;
background-image: url(http://192.168.1.81:8081/videostream.cgi);
background-size: 980px 735px;
background-repeat: no-repeat;

Well this works fine on local network but no video on port forward to the server on port 80.

I think the video would work if it wasnt pulling from a local address and port 8081.

Pete
on August 11, 2015 at 8:24 pm said:

Great Article! I see the last update to the executable was November 2013 Is this effort dead and if so, what are people using instead?

rbn2013
on August 11, 2015 at 9:39 pm said:

As you say Pete it is rather an old article. I think things have moved on a bit. Personally I have been trying out various other ideas.
First this article on using OpenCV http://www.pyimagesearch.com/2015/06/01/home-surveillance-and-motion-detection-with-the-raspberry-pi-
python-and-opencv/
Secondly I have been playing with the new telegram bot api. This looks exciting as a means for communicating with a mobile phone and sending it
video motion captures. I am currently playing with a PIR triggering a Pi camera to record 10 seconds and then for the bot to send it to my iPhone.
I got ideas for this from http://www.pyimagesearch.com/2015/06/01/home-surveillance-and-motion-detection-with-the-raspberry-pi-python-and-
opencv/ and details on the telegram bot from https://www.domoticz.com/wiki/Telegram_Bot .This last site in fact carries details of a comprehen
sive home automation centre. I am also experimenting with a python telegram bot wrapper from https://pypi.python.org/pypi/python-telegram-
bot/1.8 Frankly I am amazed at the number of hits my article still gets considering how old it is.
I hope to write up some of my new experiences before too long.

Cdric Verstraeten
Cdric Verstraeten
on October 18, 2015 at 7:38 pm said:

Instead of motion you can also use Kerberos.io, its also open-source and a lot more user friendly to install and configure. You can find more information on
the website.

Graham
on November 8, 2015 at 11:54 am said:

I must have done something wrong But what I dont know


The Pi Camera refuses to start , when I test in the mmal dir , using :-
pi@raspberrypi ~/mmal $ ./motion-mmal -n -c motion-mmalcam.conf
I Get this
./motion-mmal: error while loading shared libraries: libavformat.so.53: cannot open shared object file: No such file or directory

Please help me
Graham

Graham
on November 8, 2015 at 12:53 pm said:

Hi Cedric , being a Total newbee to RPi so sorry if this is a repeat Qu

I Installed as per Tutorial ( Cut&Paste via SSH) , which I found to be excellent , as many others simply assume one has Knowledge of RPi .
I also used you latest Conf file from Drop Box , however my RPI camera refuses to start , with the line
pi@raspberrypi ~/mmal $ ./motion-mmal -n -c motion-mmalcam.conf
I then get the message
./motion-mmal: error while loading shared libraries: libavformat.so.53: cannot open shared object file: No such file or directory
Your assistance & help would be greatly appreciated
Regards
Graham

rbn2013
on November 8, 2015 at 2:54 pm said:

I think this is probably because you are using the latest distro Jessie rather than Wheezy which was in force when this article was written. The
same comment has appeared in the Raspberry Pi forum. One user has posted a possible solution that you could try. https://www.raspberryp
i.org/forums/viewtopic.php?f=91&t=123397 Hope this will help. This article is now very old, and I am afraid that there will increasingly be the likely
hood of problems occurring with it as new software releases occur.

Tony
on December 20, 2015 at 7:50 am said:

nice step by step tutorial, love the details.


Ive been tweaking around with motion for the last few month, everything works fine except safari on iOS devices, snooping google there was several
suggestion about MJPEG support on safari but nothing concrete..
are you able to see the stream from an iphone, ipad device? what am I missing here? firefox, chrome works just fine but safari displays the first image and
then blank.
any ideas?

Cheers!
Tony

rbn2013
on December 21, 2015 at 8:17 pm said:

This is now a very old article. I suggest you look at https://github.com/silvanmelchior/RPi_Cam_Web_Interface which is much more up today and
will work I think with a smart phone. See further details in http://elinux.org/RPi-Cam-Web-Interface#Basic_Installation

Bart
on January 4, 2016 at 11:36 am said:

Hi,

Nice tutorial! works like a charm!

I want to implement the ./startmotion and ./stopmotion in into python script and execute them via subprocess.call().
This works great as long as i execute the python script is executed as user Pi.
But also have GPIO pins involved in the script, so i have to execute the python script with SUDO. But as soon as i start using SUDO to execute the python
script the camera doesnt react anymore on the startmotion and stopmotion scripts when called via subprocess.call().
(i used chmod 755 on all scripts)
does anybody as an idea what goes wrong here?

You might also like