Page 1 of 1

Using on-camera motion detection

Posted: Mon Dec 01, 2014 7:07 pm
by patpend
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?

Re: Using on-camera motion detection

Posted: Fri Jan 02, 2015 10:38 pm
by farmercyst
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

Re: Using on-camera motion detection

Posted: Sat Jan 03, 2015 4:00 am
by sime
i'm very interested...

that would save a lot of cpu....

Simon

Re: Using on-camera motion detection

Posted: Sat Jan 03, 2015 5:44 am
by farmercyst
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 :)

Re: Using on-camera motion detection

Posted: Tue Jun 09, 2015 5:51 pm
by patpend
Do you use a separate FTP dir and running script for each camera?

Re: Using on-camera motion detection

Posted: Thu Jun 11, 2015 11:52 pm
by asker
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