How do I trigger my custom code on a motion event?

dingbatca

n3wb
Joined
Jun 25, 2015
Messages
11
Reaction score
5
Very long story short, I am trying to use HikVision's built in motion sensing to trigger an event in ZoneMinder.

Running firmware 5.2.5 on all my cameras. Have full command line access. Just need to figure out where to splice in my custom code when a motion event starts. Any ideas?

For those are wondering, this involves sending a string (1|on+20|1|External Motion|External Motion) to port 6802 on my zoneminder server:
https://wiki.zoneminder.com/How_to_use_your_external_camera's_motion_detection_with_ZM

In my case this would look something like (As tested on my DS-2CD2132-I)
Code:
# echo "1|on+20|1|External Motion|External Motion" | /dav/nc 192.168.0.5 6802
1|on|1463784221|6067
1|off|1463784243|6067
 

Enabler

Getting the hang of it
Joined
Oct 11, 2015
Messages
265
Reaction score
41
Location
Bolton
You might want to look into ONVIF and monitoring events. That way you can have a script on a server, login and register for event notifications with the camera, and as soon as there is an event you are interested your server is notified via the connection already established and your script can do your netcat command (or whatever you want).

Or you could try to monitor the output of the ouputOpen command (with maybe a pertinent setDebug) and parse it for what you want on the camera itself.

I'd go for the first one myself.
 

dingbatca

n3wb
Joined
Jun 25, 2015
Messages
11
Reaction score
5
So I can see a path forward with both.

ONVIF. I installed the python-onvif package on my zoneminder box and I can talk to the camera, but after that I am out of ideas. No clue how this ONVIF stuff works and google is not helping. The whole SOAP/ONVIF interface is WAY out side my skill set. :-(

ouputOpen. Now this is much more my style (Linux Admin by trade). I can see the camera dumping a lot of information. If I redirect that to my zoneminder systems using netcat and hijacking the built in /dav/initrun.sh so the redirect starts on boot. I could simply setup a parser on the zoneminder side that would take action based on X event. Do you have any examples of motion events from outputOpen?

I think the ONVIF option would be much cleaner and scale to multi vendors, but I am at a loss on how to set that one up.
 

dingbatca

n3wb
Joined
Jun 25, 2015
Messages
11
Reaction score
5
Code:
[05-25 14:11:02][pid:849][ALARM_EXP][DEBUG]motDetCtrl: Chan 1 motion detected.
 

dingbatca

n3wb
Joined
Jun 25, 2015
Messages
11
Reaction score
5
To be a bit more wordy for those who follow. Logged into the camera via ssh
Code:
setDebug -m ALL -l 0
setDebug -m ALARM_EXP -l 7

outputOpen
[05-25 14:39:02][pid:849][ALARM_EXP][DEBUG]motDetCtrl: chan 1 trigger rec start, chans = 0x2
[05-25 14:39:02][pid:849][RECORD][DEBUG]recordSchedule: receive MOTION_TRIGGER_REC, chans = 0x1, motionChan=1, action=1
[05-25 14:39:02][pid:849][ALARM_EXP][DEBUG]excepCtrl: chan 1 motion start.
[05-25 14:39:02][pid:849][ALARM_EXP][DEBUG]received message from g_alarm_tohost_mqd, alarm_type: 0
[05-25 14:39:02][pid:849][ALARM_EXP][DEBUG]motDetCtrl: Chan 1 motion detected.
[05-25 14:39:02][pid:849][ALARM_EXP][DEBUG]Send the alarm msgs to the ehome module, send_allalarm_info.alarmtype=0, send_allalarm_info.netret_alarm.net_alarminfo.alarmType=3.
[05-25 14:39:02][pid:849][ALARM_EXP][DEBUG]psia_PostAlarmToCenter err!
[05-25 14:39:03][pid:849][ALARM_EXP][DEBUG]Send the alarm msgs to the ehome module, send_allalarm_info.alarmtype=0, send_allalarm_info.netret_alarm.net_alarminfo.alarmType=3.
[05-25 14:39:03][pid:849][ALARM_EXP][DEBUG]received message from g_alarm_tohost_mqd, alarm_type: 0
[05-25 14:39:03][pid:849][ALARM_EXP][DEBUG]psia_PostAlarmToCenter err!
[05-25 14:39:04][pid:849][ALARM_EXP][DEBUG]Send the alarm msgs to the ehome module, send_allalarm_info.alarmtype=0, send_allalarm_info.netret_alarm.net_alarminfo.alarmType=3.
<Lots of the same>
[05-25 14:40:16][pid:849][ALARM_EXP][DEBUG]received message from g_alarm_tohost_mqd, alarm_type: 0
[05-25 14:40:16][pid:849][ALARM_EXP][DEBUG]psia_PostAlarmToCenter err!
[05-25 14:40:16][pid:849][ALARM_EXP][DEBUG]motDetCtrl: chan 1 trigger rec stop, chans = 0x2
[05-25 14:40:16][pid:849][ALARM_EXP][DEBUG]motDetCtrl: Chan 1 motion stop.
[05-25 14:40:16][pid:849][ALARM_EXP][DEBUG]excepCtrl: chan 1 motion stop, time=1464187216.
[05-25 14:40:16][pid:849][ALARM_EXP][DEBUG]Send the alarm msgs to the ehome module, send_allalarm_info.alarmtype=0, send_allalarm_info.netret_alarm.net_alarminfo.alarmType=3.
As a different point of interest, I can also find the ONVIF event:
Code:
[05-25 14:39:03][pid:849][RECORD][DEBUG]inputONVIFInfo:t:1464187143, ret:132, chan 1, type 0x1001.
[05-25 14:40:17][pid:849][RECORD][DEBUG]inputONVIFInfo:t:1464187217, ret:132, chan 1, type 0x1002.
Now I really wish I could figure out how to catch these events with ONVIF from Linux.
 
Top