Just in case it helps anyone (maybe myself in a few weeks when I've forgotten what I did...) here's what I did to get 'motion' to auto-start and work correctly on powerup. As recommended elsewhere, I have two simple scripts to start and stop the process:
Code: Select all
pi@rp5:~/mmal$ cat startmotion
#!/bin/sh
nohup /home/pi/mmal/motion-mmal -n -c /home/pi/mmal/cmmal.conf 1>/dev/null 2>&1 </dev/null &
pi@rp5:~/mmal$ cat stopmotion
#!/bin/sh
ps -ef | grep motion-mmal | awk '{print $2}' | xargs kill
I am using the utility "sitecopy" (sudo apt-get install sitecopy) to upload stills and videos from the directory on my Pi to a remote webserver. It gets triggered to upload any changed files in my still/video directory each time a new video is saved. Now, my sitecopy config file is in the home directory for user 'pi', but the motion-mmal process is running as root from rc.local
Code: Select all
added to file: /etc/rc.local
# start the motion service (runs as root!)
/home/pi/mmal/startmotion
so I need to change my process user-ID to make this work. I use 'sudo -u pi' inside my config file: /home/pi/mmal/cmmal.conf (note 'sitecopy -u bcpics' means "update any changed files from local to remote site, the one named bcpics in the ~/.sitecopyrc config file")
Code: Select all
# Command to be executed when a movie file (.mpg|.avi) is closed. (default: none)
# To give the filename as an argument to a command append it with %f
on_movie_end sudo -u pi sitecopy -u bcpics
I use a PHP script on the remote server to generate a separate index of JPEG and AVI files. Sorting by name is OK because the name is also the file creation date.
Code: Select all
<?php
echo "<b>Current Files:</b><br><hr><br>";
$dir = ".";
$files = scandir($dir, 0); // in ascending order
$i = 1;
foreach($files as $file) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
if (is_file($file) && ($ext == "jpg")) {
echo $i;
echo ": <a href='$file'>$file</a>";
if (($i%3) == 0) { // display in three columns, 'cause that fits nicely
echo "<br>", PHP_EOL;
} else {
echo " ", PHP_EOL;
}
$i = ($i + 1);
}
}
echo "<br><hr><br>";
$i = 1;
foreach($files as $file) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
if (is_file($file) && ($ext == "avi")) {
echo $i;
echo ": ";
$fsk = intval((filesize($file)) / 1024);
echo $fsk;
echo ": <a href='$file'>$file</a>";
if (($i%3) == 0) {
echo "<br>", PHP_EOL;
} else {
echo " ", PHP_EOL;
}
$i = ($i + 1);
}
}
?>
Example output (filenames are clickable links on the actual webpage). For the video files, I include the size in kBytes so I can see at a glance which are longer or shorter.
Code: Select all
Current Files:
1: 01-2013_0729_1701_14.jpg 2: 02-2013_0729_1707_05.jpg 3: 03-2013_0729_1708_28.jpg
4: 04-2013_0729_1709_12.jpg 5: 05-2013_0729_1726_51.jpg 6: 06-2013_0729_1726_56.jpg
7: 07-2013_0729_1727_06.jpg 8: 08-2013_0729_1727_09.jpg
1: 533: 01-2013_0729_1701_13.avi 2: 166: 02-2013_0729_1707_05.avi 3: 112: 03-2013_0729_1708_27.avi
4: 114: 04-2013_0729_1709_12.avi 5: 75: 05-2013_0729_1726_51.avi 6: 207: 06-2013_0729_1726_54.avi
7: 139: 07-2013_0729_1727_05.avi 8: 59: 08-2013_0729_1727_09.avi