ZM and on-camera motion detection related modifications

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
cayfer
Posts: 3
Joined: Thu Dec 20, 2007 4:17 pm
Location: Ankara/Turkey

ZM and on-camera motion detection related modifications

Post by cayfer »

I've been using ZM for more than a year now.

I've recently decided to use the the on-camera motion detection feature of the AXIS 207 cameras that we have been using. (Motion detection with ZM puts a lot of burden on the server; if one has more than 5-6 cameras, the ZM server must be really a powerful computer).

The new (most recent) AXIS-207 firmware allows the camera to send a tcp message to zmtrigger.pl running on a predefined server once some motion is detected by the camera.

I had described how I set up my Axis207 and ZM to utilize the on-camera motion detection here http://www.zoneminder.com/forums/viewto ... highlight=

The message sent by the camera to ZM has the format:

Code: Select all

mon_id|on 20|score|some text|some other text
an example for a message sent by monitor 8 would be

Code: Select all

8|on 20|50|Alarm on cam 8|Camera detected some motion
The above message means recording of "camera 8" must start and last for 20 seconds. zmtrigger.pl handles this message as follows:

recording starts immediately when the `on` message is received and an 'event cancel' action is scheduled for current_time+20 seconds.

The AXIS 207 fires messages everytime it detects motion and this firing continues every few seconds as long as the motion continues. The problem is that; when a motion is detected at t=1. recording starts at t=1 but a "cancel" action is scheduled to t=21 and no matter what is going on; recording stops at t=21. In real life, in case of continuing motion; one wants recording to be continued as long as the motion continues. That is to say, a motion detection occurring at t=12 should extend recording till t=32. With the current zmtrigger.pl, a "recording cancel" action is scheduled at t=21 once a message is received at t=1 telling zmtrigger to record for 20 seconds.

I've modified zmtrigger.pl so that if a "start recording" message is received while the camera is in alarm state (that is: it is already recording): the previous `cancel` action will be cancelled and a new cancel action will be scheduled for t+20. This way I can record the whole motion completely regardless of its duration.


My code modification on the zmtrigger.pl file to cancel a "cancel" action when a message is received for cameras already in alarm state is in the following block:

Frankly; I couldn't simply delete a scheduled 'cancel' event in the complicated data structure maintained by zmtrigger but; instead i set the camera ID of a previously set action to 999. The cost of this is having a warning message complaining that camera `999` cannot be found. No worries with that...

Code: Select all

if ( $delay )
                {
                        my $action_time = time()+$delay;
                        my $action_text = $id."|cancel";
                        my $action_array = $actions{$action_time};
                        if ( !$action_array )
                        {
                                $action_array = $actions{$action_time} = [];
                        }
                        #
                        if (  zmInAlarm($monitor)  )   {
                             # delete any previously registered "cancel" time event(s) for this monitor

                             foreach my $cua_key (keys(%actions)) {
                                foreach my $cua_action ( @{$actions{$cua_key}} )
                                {
                                    my $cua_message = $cua_action->{message};
                                    my $cua_connection = $cua_action->{connection};
                                    if ($cua_message eq $id."|cancel") {
                                         $cua_action->{message} = '999|cancel';
                                    }
                                }
                             }

                        }

                        push( @$action_array, { connection=>$connection, message=>$action_text } );


User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

The difficulty in cancelling a cancel may be a more general issue with zmtrigger.pl so I will look at a seeing if I can provide a facility to remove the need for you to hack it so much for your mod.
Phil
Post Reply