Using on-camera motion detection

Forum for questions and support relating to the 1.28.x releases only.
Post Reply
patpend
Posts: 43
Joined: Thu Mar 13, 2014 12:23 pm

Using on-camera motion detection

Post by patpend » Mon Dec 01, 2014 7:07 pm

Is anyone using on-camera motion detection with Grandstream cameras? Possibly using the "Alarm HTTP server" setting to communicate motion triggers to zmtrigger.pl, similar to what's described in the Axis motion detection wiki?

farmercyst
Posts: 2
Joined: Fri Jan 02, 2015 10:15 pm

Re: Using on-camera motion detection

Post by farmercyst » Fri Jan 02, 2015 10:38 pm

If you can save to an ftp server or network folder, you can do something like I did with my foscam fi9821w. When my camera detects motion, it saves a snapshot to an ftp server. I wrote a bash script that uses inotify to monitor the folder for files added. When it detects a new file, it uses zmtrigger to put my monitor into an alarm state. I'll attach the script in hopes it helps you or someone else in the future (I'm no programmer and I knew nothing about writing a bash script before this so it is probably crap but gets the job done!).

edit: I seem to be failing with this attachment. The forum says I've met my quota on attachments and I cant link to an outside site (dropox) so I'll copy and paste.

Code: Select all

#!/bin/bash
#

zmHost=192.168.1.103
zmPort=6802
zmCamId=8
zmAlarmState="off" #default alarm to off
zmScore="1"
zmCause="foscam motion detection"
snapshotDir="/home/ftpuser/ftpUploads/webCamSnapshots/change/me"

# Send a ZoneMinder trigger
zmtrigger() {
    zmAlarmState="$1"
    echo "$zmCamId|$zmAlarmState|$zmScore|$zmCause|none|none" >/dev/tcp/"$zmHost"/"$zmPort"
}

latestfile() {
    unset -v latest
    for file in "$snapshotDir"/*; do
        [[ $file -nt $latest ]] && latest=$file
    done
    echo "$file"
}

#monitor the ftp directory the foscam saves motion snapshots to.
while inotifywait -e create "$snapshotDir"; do  
    alarmTime=$(date +%s)
    alarmSnapshot=$(latestfile)

    if [ "$zmAlarmState" == "off" ]; then
        zmtrigger "on"
        latestSnapshot=$(latestfile)
        alarmTime=$(date +%s)
    fi
	
    until [ "$zmAlarmState" == "off" ] && [ "$alarmSnapshot" == "$latestSnapshot" ]; do
		
		#check if another motion snapshot was added to the dir. 
		#If yes, reset alarm variables.
		#If no, check if theres been at least 6 seconds from the last snapshot
		
	    if [ "$alarmSnapshot" != $(latestfile) ]; then
		    alarmSnapshot=$(latestfile)
			alarmTime=$(date +%s)
            latestSnapshot=$(latestfile)
			
		elif [ "$(($(date +%s)-$alarmTime))" -ge 6 ]; then #I set 6 seconds because my camera takes snapshot every 5 seconds while detecting motion
		    zmtrigger "off"
		fi
		# wait one second and check again.
        sleep 1

        done
done
Last edited by farmercyst on Sat Jan 03, 2015 5:48 am, edited 2 times in total.

sime
Posts: 26
Joined: Thu Jan 01, 2015 8:45 pm

Re: Using on-camera motion detection

Post by sime » Sat Jan 03, 2015 4:00 am

i'm very interested...

that would save a lot of cpu....

Simon

farmercyst
Posts: 2
Joined: Fri Jan 02, 2015 10:15 pm

Re: Using on-camera motion detection

Post by farmercyst » Sat Jan 03, 2015 5:44 am

sime wrote:i'm very interested...

that would save a lot of cpu....

Simon
Exactly the point! This is the only way I could use 720p with this camera. I can add a few more now :)

patpend
Posts: 43
Joined: Thu Mar 13, 2014 12:23 pm

Re: Using on-camera motion detection

Post by patpend » Tue Jun 09, 2015 5:51 pm

Do you use a separate FTP dir and running script for each camera?

User avatar
asker
Posts: 1106
Joined: Sun Mar 01, 2015 12:12 pm

Re: Using on-camera motion detection

Post by asker » Thu Jun 11, 2015 11:52 pm

patpend wrote:Is anyone using on-camera motion detection with Grandstream cameras? Possibly using the "Alarm HTTP server" setting to communicate motion triggers to zmtrigger.pl, similar to what's described in the Axis motion detection wiki?
I used to use it for my foscams
http://www.zoneminder.com/wiki/index.ph ... on_with_ZM
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests