Bosse_B
Posts: 1121
Joined: Thu Jan 30, 2014 9:53 am

Can Pi2 be used as a webcam surveillance center?

Tue Feb 10, 2015 1:02 pm

I have tried to find some good examples/howto for creating a security system using a Pi.
I found this webpage but it deals with an old PiB model (pre B+) and therefore also the associated software/operating system.

My questions are:
1) Will the Pi2 be OK for the software discussed in the above webpage?
For example it uses:

Code: Select all

sudo apt-get install rpi-update
sudo rpi-update
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install motion
Since the webpage is dated in Sept 2013 I wonder amongst other about rpi-update, is that really needed and does it work on the Pi2? By what I have read it gives you the bleeding edge testing version of the firmware and I am not really keen on deviating from stable...

2) Is motion compatible with Pi2 in the first place?

3) Are there other solutions to the surveillance system using a Pi2 that you can recommend?

I will go and get the hardware fresh from the store for this project, and I would like to use the latest Pi technology.

Any advice welcome!
Bo Berglund
Sweden

User avatar
RaTTuS
Posts: 10777
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Can Pi2 be used as a webcam surveillance center?

Tue Feb 10, 2015 1:08 pm

How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Bosse_B
Posts: 1121
Joined: Thu Jan 30, 2014 9:53 am

Re: Can Pi2 be used as a webcam surveillance center?

Wed Feb 11, 2015 9:06 am

After looking around a bit I am now curious to know if the Pi camera can be used with the module "motion" used in the HOWTO I linked to in my first post.
I.e. can one make a surveillance system without using a USB connected webcam?
If so are there any tutorials around?
Bo Berglund
Sweden

Ant232
Posts: 115
Joined: Thu Jul 12, 2012 9:34 pm

Re: Can Pi2 be used as a webcam surveillance center?

Wed Feb 11, 2015 9:35 am

1+ to MotionPie

I have tried it out on the Pi 2 with the Pi camera and it works well. Not sure if it is optimized to use all 4 cores yet but it does work.
It's only a 42mb image so is very light weight. It was pretty much plug and play.
I didn't have time to test it in detail but initial results very promising.

mjb152
Posts: 22
Joined: Mon Feb 09, 2015 10:46 pm

Re: Can Pi2 be used as a webcam surveillance center?

Wed Feb 11, 2015 10:28 am

is it just motion detection you're after ?
I'm playing with raspistill to generate time-lapse videos, it's works great. Using mencoder to stitch all the photos together, or ffmpeg on a mac (bit quicker).
I've got a small web server that lets you take an immediate snapshot, or view the time-lapse videos, works surprisingly well.

Bosse_B
Posts: 1121
Joined: Thu Jan 30, 2014 9:53 am

Re: Can Pi2 be used as a webcam surveillance center?

Wed Feb 11, 2015 10:51 am

For the time being I bought a Logitech C270 webcam so I could familiarize myself with setting up motion.
The tutorial I found seems not to be completely accurate because there are conf options that seem not to exist anymore...
But the most problematic is the option videodevice, it is set by default in the conf file to /dev/video0 and this is not listed when I do a ls -l /dev
So I guess that my webcam has registered as some other kind of device...
lsusb lists the webcam as:

Code: Select all

Bus 001 Device 007: ID 046d:0825 Logitech, Inc. Webcam C270
So it seems to have been detected at least.
But what is the correct videodevice for motion?
Is there a command to show for which device a certain hardware resource (like the one above) is used?
Bo Berglund
Sweden

Bosse_B
Posts: 1121
Joined: Thu Jan 30, 2014 9:53 am

Re: Can Pi2 be used as a webcam surveillance center?

Wed Feb 11, 2015 10:54 am

mjb152 wrote:is it just motion detection you're after ?
Well, I am thinking of setting up a camera to monitor my vacation home. I would like to be able to log on and watch the video from the camera and also to have it detect if something is happening, like a burglar entry, at which time it should save some images of that.
And while I am living there I would like to set up the same at home so I can watch if something untowards happens.
Bo Berglund
Sweden

mjb152
Posts: 22
Joined: Mon Feb 09, 2015 10:46 pm

Re: Can Pi2 be used as a webcam surveillance center?

Wed Feb 11, 2015 11:16 am

ditto, I'm trying to set something up this week before I head out there.
I bought the camera which plugs directly into the Pi, it works really well. Bought a clear case and also a small camera container off eBay (just to protect the board), and I've simply taped that on top of the case.
My first tests have been with raspistill and rapsivid, and they both work well. For now I'm happy with it taking snapshots every 10 seconds (for time-lapse), but also want to expand the script so that I can override that with the browser to enable me to take an instant snapshot or video, then start again when I'm done.
At some point I'd like to add motion detection to this config.

Bosse_B
Posts: 1121
Joined: Thu Jan 30, 2014 9:53 am

Re: Can Pi2 be used as a webcam surveillance center?

Wed Feb 11, 2015 10:32 pm

Had to manually create the /dev/video0 device:

Code: Select all

sudo mknod /dev/video0 c 81 0
Then I also rebooted the Pi.
Now I get a picture served out, but at very low quality, a far cry from the 720p the camera delivers. :(
I tried to change height and width in the motion.conf file (was defaulted to 360x240).
But then the Pi would not even start motion so I had to back it down.
Now I have quality set to 100 (%) and 360x240 pixel size and it is pretty dismal....

Anyone in the know how to get the Logitech C270 webcam to perform better with motion?
Or is there some other better software?
Bo Berglund
Sweden

cpc464
Posts: 238
Joined: Tue Jul 08, 2014 5:10 pm
Contact: Website

Re: Can Pi2 be used as a webcam surveillance center?

Thu Feb 12, 2015 10:57 pm

Hi Bo

I have a Pi 1 that works well with motion and a Logitech Quickcam 9000 Pro (the forerunner of the C270). A slight problem is that you can't adjust the focus of this camera from Linux. Distant objects are therefore blurred (very slightly). It takes good, large pictures with Motion.

I was thinking about getting a C270 and am surprised to hear about the /dev/video problem. The C270 is compatible with video4linux I think, so it should work on the Pi. It is a wide screen camera so perhaps you need wide screen resoltions in motion.conf ?

Last year I wrote this guide on setting up Motion with the Pi:
http://unixetc.co.uk/2014/01/20/simple- ... pberry-pi/

It is working well on the Pi 1 with these resolutions in motion.conf:
width 1280
height 960

You might have to attach the C270 to Windows and check the default settings. More here
http://forums.logitech.com/t5/Webcams/R ... d-p/756268

Cheers,
Jim
Unix engineer since 1989

Bosse_B
Posts: 1121
Joined: Thu Jan 30, 2014 9:53 am

Re: Can Pi2 be used as a webcam surveillance center?

Sun Feb 15, 2015 2:20 pm

Thanks for the guide description!
Question:
If I set motion up as you described to take regular widely separated images, is it also possible to set it up to trigger on motion detection and then take a short video (say 15 s) and store it, then revert to still image mode?

I am eagerly waiting for the Pi2 to no longer be out of stock at the electronics stores in my neighborhood.
Since it has more punch it would be a better choice than the PiB(512M) I have now in order to handle videos, I guess.

Incidentally I finally got the 1280x960 resolution working as a streaming video cam, but I don't know what it took to get there and unfortunately I did it before reading your guide on the importance of taking a backup of the conf file before editing it.... :(
Is there any way to retrieve the original conf file somewhere so I can do a diff?
Bo Berglund
Sweden

cpc464
Posts: 238
Joined: Tue Jul 08, 2014 5:10 pm
Contact: Website

Re: Can Pi2 be used as a webcam surveillance center?

Mon Feb 16, 2015 6:03 pm

I don't think the Pi 1 is any worse at running motion than the Pi 2.

Yes you can set up motion to take videos as well as regular stills. Just turn on the following option in the config file:
ffmpeg_cap_new on

Along with
output_normal off

and
snapshot_interval 600

motion should start taking snapshots every 10 minutes as well as videos when motion is detected. I haven't actually tested it though.

Jim
Unix engineer since 1989

JayTay79
Posts: 4
Joined: Mon Feb 16, 2015 10:21 pm

Re: Can Pi2 be used as a webcam surveillance center?

Mon Feb 16, 2015 10:26 pm

FWIW I'm using an A+ with the camera module running motionPie and it's working absolutely fine. I also have another A+ running Raspbian with MotionEye as the camera software, also with no issues. I initially set up motion but found I had a lot of display issues with the various browsers I use day to day whereas motionEye/Pi work flawlessly on every browser I've tried.

Bosse_B
Posts: 1121
Joined: Thu Jan 30, 2014 9:53 am

Re: Can Pi2 be used as a webcam surveillance center?

Tue Feb 17, 2015 7:00 am

I have a question about the names of the snapshot image files:
What I see is the following file names (example from tonight):

Code: Select all

01-20150217003000-snapshot.jpg
02-20150217004000-snapshot.jpg
04-20150217005000-snapshot.jpg
04-20150217010000-snapshot.jpg
04-20150217011000-snapshot.jpg
05-20150217012000-snapshot.jpg
05-20150217013000-snapshot.jpg
05-20150217014000-snapshot.jpg
05-20150217015000-snapshot.jpg
05-20150217020000-snapshot.jpg
05-20150217021000-snapshot.jpg
05-20150217022000-snapshot.jpg
05-20150217023000-snapshot.jpg
05-20150217024000-snapshot.jpg
05-20150217025000-snapshot.jpg
05-20150217030000-snapshot.jpg
05-20150217031000-snapshot.jpg
05-20150217032000-snapshot.jpg
05-20150217033000-snapshot.jpg
09-20150217072000-snapshot.jpg
09-20150217073000-snapshot.jpg
10-20150217074000-snapshot.jpg
What is the initial 2-digit number? The remaining part is just a timestamp and the snapshot text, but I see no logic in the leading number....
The motion.conf file has this entry:
snapshot_filename %v-%Y%m%d%H%M%S-snapshot
So the %v is what casues the extra number, but there is no explanation as to what it actually means except this:
# %v = event, %q = frame number, %t = thread (camera) number,

event?????

I want to create a webpage where the last 20 images are shown as clickable thumbnails but with this extra number in the file name it is hard for me to see what I should place into the html file so it would display these.

Do I need to go to PHP in order to resolve this?
Bo Berglund
Sweden

JayTay79
Posts: 4
Joined: Mon Feb 16, 2015 10:21 pm

Re: Can Pi2 be used as a webcam surveillance center?

Tue Feb 17, 2015 9:25 am

Bosse_B wrote: So the %v is what casues the extra number, but there is no explanation as to what it actually means except this:
# %v = event, %q = frame number, %t = thread (camera) number,
An "event" is a period of activity that triggers the camera, this may mean you have one event with just one image and a second event event with 20 images depending on what the camera has picked up.

Bosse_B
Posts: 1121
Joined: Thu Jan 30, 2014 9:53 am

Re: Can Pi2 be used as a webcam surveillance center?

Tue Feb 17, 2015 2:55 pm

I ended up removing %v- from the filename template in motion.conf...

Further on using motion:
Now that I seem to have configurations in place for motion, the next step is to make it run at RaspBian startup.
The problem I see is that the way I have found is to create a shell-script file and put it into /etc/init.d and the script shall respond to arguments start and stop.
The first part (start) seems simple enough, I guess one sets up motion for daemon mode and then just enters
motion;
on a script line. But how can one stop motion via the stop argument?
The shell-script would have to be able to tell motion to stop, but since it is now running in daemon mode, how can one stop it????
Seems rather impossible to me.

Of course there must be a way, but I could not figure it out... :(
Bo Berglund
Sweden

3corey2
Posts: 85
Joined: Sun Feb 15, 2015 2:59 am

Re: Can Pi2 be used as a webcam surveillance center?

Tue Feb 17, 2015 3:19 pm

yes
ras pi 2, gotta love it.

Bosse_B
Posts: 1121
Joined: Thu Jan 30, 2014 9:53 am

Re: Can Pi2 be used as a webcam surveillance center?

Tue Feb 17, 2015 4:31 pm

Thanks, that was clear.... :shock:
Bo Berglund
Sweden

JayTay79
Posts: 4
Joined: Mon Feb 16, 2015 10:21 pm

Re: Can Pi2 be used as a webcam surveillance center?

Tue Feb 17, 2015 7:58 pm

You should be able to set it to run as a daemon by editing /etc/default/motion and changing the "start_motion_daemon" value. If so then you should be able to start it with "sudo service motion start" and stop it with "sudo service motion stop".

Bosse_B
Posts: 1121
Joined: Thu Jan 30, 2014 9:53 am

Re: Can Pi2 be used as a webcam surveillance center?

Tue Feb 17, 2015 8:51 pm

Thanks,
I will try that!
Now I have found another problem, the cron command to prune the snapshot files somehow screws up after a while and leaves a bunch of old files.
The cron script looks like this:

Code: Select all

15 * * * * (date; ls /var/www/webcam/*snapshot.jpg | tail -n +20 | xargs rm -v) >> /tmp/images_deleted 2>&1
At first it seemed to work but then when I looked after a few hours I had this:

Code: Select all

pi@raspbian-pi /var/www/webcam $ ls -l
total 2012
-rw-r--r-- 1 root root  92596 Feb 17 12:20 20150217122000-snapshot.jpg
-rw-r--r-- 1 root root  89442 Feb 17 12:30 20150217123000-snapshot.jpg
-rw-r--r-- 1 root root  89511 Feb 17 12:40 20150217124000-snapshot.jpg
-rw-r--r-- 1 root root  89091 Feb 17 12:50 20150217125000-snapshot.jpg
-rw-r--r-- 1 root root  91563 Feb 17 13:00 20150217130000-snapshot.jpg
-rw-r--r-- 1 root root  92372 Feb 17 13:10 20150217131000-snapshot.jpg
-rw-r--r-- 1 root root  87654 Feb 17 13:20 20150217132000-snapshot.jpg
-rw-r--r-- 1 root root  86954 Feb 17 13:30 20150217133000-snapshot.jpg
-rw-r--r-- 1 root root  88311 Feb 17 13:40 20150217134000-snapshot.jpg
-rw-r--r-- 1 root root  89906 Feb 17 13:50 20150217135000-snapshot.jpg
-rw-r--r-- 1 root root  91680 Feb 17 14:00 20150217140000-snapshot.jpg
-rw-r--r-- 1 root root  90232 Feb 17 14:10 20150217141000-snapshot.jpg
-rw-r--r-- 1 root root  91820 Feb 17 14:20 20150217142000-snapshot.jpg
-rw-r--r-- 1 root root  90793 Feb 17 14:30 20150217143000-snapshot.jpg
-rw-r--r-- 1 root root  87372 Feb 17 14:40 20150217144000-snapshot.jpg
-rw-r--r-- 1 root root  87649 Feb 17 14:50 20150217145000-snapshot.jpg
-rw-r--r-- 1 root root  92543 Feb 17 15:00 20150217150000-snapshot.jpg
-rw-r--r-- 1 root root  90235 Feb 17 15:10 20150217151000-snapshot.jpg
-rw-r--r-- 1 root root  91970 Feb 17 15:20 20150217152000-snapshot.jpg
-rw-r--r-- 1 root root 100935 Feb 17 21:20 20150217212000-snapshot.jpg
-rw-r--r-- 1 root root 100160 Feb 17 21:30 20150217213000-snapshot.jpg
-rw-r--r-- 1 root root 100460 Feb 17 21:40 20150217214000-snapshot.jpg
lrwxrwxrwx 1 root root     27 Feb 17 21:40 lastsnap.jpg -> 20150217214000-snapshot.jpg
As you can see only the last 3 files are actually new, all of the others are leftovers from about 6 hours or more earlier.
I take a snapshot every 10 minutes.
I got the cron script from the Simple Webcam howto page as suggested here earlier in this thread.

There must be an error somewhere in setting up cron...
Bo Berglund
Sweden

cpc464
Posts: 238
Joined: Tue Jul 08, 2014 5:10 pm
Contact: Website

Re: Can Pi2 be used as a webcam surveillance center?

Tue Feb 17, 2015 10:08 pm

Hi Bo

That cron job is not part of motion, it is part the how-to guide (which I wrote). If you have more questions about the guide, please post them to the guide comment section, rather than here. Readers of this forum won't know what you are asking about.

However, to answer: the cron job appears to be working correctly. It has left the latest 20 snapshots and deleted the earlier ones. Those are the latest 20 snapshots. The varying time stamps are probably a result of you stopping and starting motion or another change (the file size difference seems to indicate a config change before the last 3 files). The log file /tmp/images_deleted should confirm.

Jim
Unix engineer since 1989

Bosse_B
Posts: 1121
Joined: Thu Jan 30, 2014 9:53 am

Re: Can Pi2 be used as a webcam surveillance center?

Tue Feb 17, 2015 10:40 pm

I know it is not part of motion, as I have stated above it is taken from your tutorial page...

Unfortunately it has not left the last snapshots...
It rather seems like every time it runs it deletes the last 6 snapshots (i.e. those created the last hour) rather than the oldest snapshots....
I have posted a part of the /tmp/images_deleted logfile in the comment to your tutorial.
The log confirms that the cron job deletes the latest snapshots to bring the list down to 20 files instead of deleting the oldest snapshots...
For clarity I also post that extract here:

Code: Select all

Tue Feb 17 21:15:01 CET 2015
removed `/var/www/webcam/20150217202000-snapshot.jpg'
removed `/var/www/webcam/20150217203000-snapshot.jpg'
removed `/var/www/webcam/20150217204000-snapshot.jpg'
removed `/var/www/webcam/20150217205000-snapshot.jpg'
removed `/var/www/webcam/20150217210000-snapshot.jpg'
removed `/var/www/webcam/20150217211000-snapshot.jpg'
Tue Feb 17 22:15:01 CET 2015
removed `/var/www/webcam/20150217212000-snapshot.jpg'
removed `/var/www/webcam/20150217213000-snapshot.jpg'
removed `/var/www/webcam/20150217214000-snapshot.jpg'
removed `/var/www/webcam/20150217215000-snapshot.jpg'
removed `/var/www/webcam/20150217220000-snapshot.jpg'
removed `/var/www/webcam/20150217221000-snapshot.jpg'
Tue Feb 17 23:15:01 CET 2015
removed `/var/www/webcam/20150217222000-snapshot.jpg'
removed `/var/www/webcam/20150217223000-snapshot.jpg'
removed `/var/www/webcam/20150217224000-snapshot.jpg'
removed `/var/www/webcam/20150217225000-snapshot.jpg'
removed `/var/www/webcam/20150217230000-snapshot.jpg'
removed `/var/www/webcam/20150217231000-snapshot.jpg'
The ls command that is part of the script must be listing the files in the opposite direction timewise from what is assumed by using tail...

EDIT:
No the listing order is not the culprit! I did a quick test:

Code: Select all

pi@raspbian-pi /var/www/webcam $ ls *snapshot.jpg > snapshots
pi@raspbian-pi /var/www/webcam $ cat snapshots
20150217122000-snapshot.jpg
20150217123000-snapshot.jpg
20150217124000-snapshot.jpg
20150217125000-snapshot.jpg
20150217130000-snapshot.jpg
20150217131000-snapshot.jpg
20150217132000-snapshot.jpg
20150217133000-snapshot.jpg
20150217134000-snapshot.jpg
20150217135000-snapshot.jpg
20150217140000-snapshot.jpg
20150217141000-snapshot.jpg
20150217142000-snapshot.jpg
20150217143000-snapshot.jpg
20150217144000-snapshot.jpg
20150217145000-snapshot.jpg
20150217150000-snapshot.jpg
20150217151000-snapshot.jpg
20150217152000-snapshot.jpg
20150217232000-snapshot.jpg
20150217233000-snapshot.jpg
20150217234000-snapshot.jpg
pi@raspbian-pi /var/www/webcam $
So this confirms that the most recent files are at the bottom of the ls list.
Very strange why the cron is working the way it is....

EDIT2:
Now I have tested various listing commands and this seems to list the oldest files rather than the newest ones:

Code: Select all

*snapshot.jpg | head --lines=-20
Now I just have to find out how I can change the cron job....
Bo Berglund
Sweden

Bosse_B
Posts: 1121
Joined: Thu Jan 30, 2014 9:53 am

Re: Can Pi2 be used as a webcam surveillance center?

Wed Feb 18, 2015 7:35 am

Now file pruning is working as it should, leaving the 20 newest files in the folder.
The crontab entry looks like this:

Code: Select all

15 * * * * (date; ls /var/www/webcam/*snapshot.jpg | head --lines=-20 | xargs rm -v) >> /tmp/images_deleted 2>&1
Bo Berglund
Sweden

cpc464
Posts: 238
Joined: Tue Jul 08, 2014 5:10 pm
Contact: Website

Re: Can Pi2 be used as a webcam surveillance center?

Mon Feb 23, 2015 9:09 pm

For the record the article

http://unixetc.co.uk/2014/01/20/simple- ... pberry-pi/

was corrected for the deletion of files. More details in the comments under the article.
Unix engineer since 1989

Bosse_B
Posts: 1121
Joined: Thu Jan 30, 2014 9:53 am

Re: Can Pi2 be used as a webcam surveillance center?

Mon Feb 23, 2015 10:20 pm

8-)
Bo Berglund
Sweden

Return to “General discussion”