sg4rb0
Posts: 20
Joined: Mon Sep 22, 2014 9:35 pm

Motion Problems

Thu Oct 01, 2015 4:09 pm

I'm trying to setup Raspberry Pi surveillance using Motion. I'm following this guide:

http://www.codeproject.com/Articles/665 ... nce-camera

When I stop the motion service and then start it, I get a nice stream and it works for like 15-20 seconds and I view it on a remote machine using http://[ip.of.rasbperry.ip]:8081. Then suddenly it just stops working. After checking the logs I see this:

pi@raspberrypi ~ $ tail -f /var/log/messages
Oct 1 16:02:35 raspberrypi motion: [1] [NTC] [STR] stream_stop: Closing motion-stream listen socket & active motion-stream sockets
Oct 1 16:02:35 raspberrypi motion: [1] [NTC] [STR] stream_stop: Closed motion-stream listen socket & active motion-stream sockets
Oct 1 16:02:35 raspberrypi motion: [1] [NTC] [VID] vid_close: Closing video device /dev/video0
Oct 1 16:02:35 raspberrypi motion: [0] [NTC] [STR] httpd_run: motion-httpd - Finishing
Oct 1 16:02:35 raspberrypi motion: [0] [NTC] [STR] httpd_run: motion-httpd Closing
Oct 1 16:02:35 raspberrypi motion: [0] [NTC] [STR] motion_web_control: motion-httpd thread exit
Oct 1 16:02:36 raspberrypi motion: [0] [NTC] [ALL] main: Threads finished
Oct 1 16:02:37 raspberrypi motion: [0] [NTC] [ALL] main: Motion terminating
Oct 1 16:02:37 raspberrypi motion: [0] [NTC] [ALL] motion_remove_pid: Removed process id file (pid file).
Oct 1 16:07:11 raspberrypi rsyslogd-2007: action 'action 17' suspended, next retry is Thu Oct 1 16:08:11 2015 [try http://www.rsyslog.com/e/2007 ]

I'm not sure what the next step is to fixing the issue. My pi is a B+, using a standard raspberry pi camera. I'm literally trying to use it just to record a video stream & don't have a PIR sensor or anything to detect movement.

sg4rb0
Posts: 20
Joined: Mon Sep 22, 2014 9:35 pm

Re: Motion Problems

Thu Oct 01, 2015 4:55 pm

Well I'm pretty sure I've figured it out. For all you guys having the same issue (I've seen loads of people having problems with this), this is what I did:

pi@raspberrypi /var/lib/motion $ sudo nano /etc/motion/motion.conf

Under this section
############################################################
# Basic Setup Mode
############################################################
logfile /tmp/motion.log


pi@raspberrypi ~ $ sudo service motion stop
pi@raspberrypi ~ $ sudo service motion start

pi@raspberrypi /var/lib $ tail -f /tmp/motion.log

I then saw some log messages saying this:
[1] [ERR] [ENC] [Oct 01 16:27:13] ffmpeg_open: url_fopen - error opening file /var/lib/motion/01-20151001162713.avi ... check access rights to target directory:
[1] [ERR] [EVT] [Oct 01 16:27:13] event_ffmpeg_newfile: ffopen_open error creating (new) file [/var/lib/motion/01-20151001162713.avi]:
[1] [NTC] [ALL] [Oct 01 16:27:13] motion_detected: Motion detected - starting event 1
[1] [ERR] [ALL] [Oct 01 16:27:13] myfopen: Error opening file /var/lib/motion/01-20151001162713-00.jpg with mode w:
[1] [ERR] [ALL] [Oct 01 16:27:13] put_picture: Can't write picture to file /var/lib/motion/01-20151001162713-00.jpg - check access rights to target directory
Thread is going to finish due to this fatal error:
[0] [NTC] [STR] [Oct 01 16:27:13] httpd_run: motion-httpd - Finishing
[0] [NTC] [STR] [Oct 01 16:27:13] httpd_run: motion-httpd Closing


So it was having errors writing to /var/lib/motion with .jpg's and then crashed "due to this fatal error".

pi@raspberrypi /tmp $ cd /var/lib/
pi@raspberrypi /var/lib $ chmod 777 motion

Problem solved. I tailed the log again and saw it saving loads of images, which I've come to realise that basically it looks like the motion software takes a picture when it detects a change in the video buffer pixels. I didn't realise it did this (I thought you needed a PIR sensor to get the motion stuff working). Pretty sweet. I would also like to add that I came across another issue when I initially followed the guide, and it was the fact I also needed to run the command below before I was able to get the camera working.

sudo modprobe bcm2835-v4l2

grangorge
Posts: 1
Joined: Thu Jan 28, 2016 3:35 pm

Re: Motion Problems

Thu Jan 28, 2016 3:37 pm

Great, works fine for me, had same problem that was driving me mad.
Now everything works fine. Thanks.

wavesailor
Posts: 2
Joined: Wed Aug 10, 2016 7:30 am

Re: Motion Problems

Wed Aug 10, 2016 9:22 am

I would NOT recommend doing:

Code: Select all

pi@raspberrypi /tmp $ cd /var/lib/
pi@raspberrypi /var/lib $ chmod 777 motion
Rather create a new sub-directory in your home and set the permissions there:

Code: Select all

mkdir  /home/pi/Monitor
sudo chgrp motion /home/pi/Monitor
sudo chmod g+rwx /home/pi/Monitor
sudo chmod -R g+w /home/pi/Monitor/
Make sure to restart the service.

User avatar
pi-anazazi
Posts: 1062
Joined: Fri Feb 13, 2015 9:22 pm
Location: EU

Re: Motion Problems

Fri Aug 12, 2016 6:44 am

@wavesailor: +1
Kind regards

anazazi

Return to “Troubleshooting”