Difference between revisions of "ZMTrigger"

From ZoneMinder Wiki
Jump to navigationJump to search
Line 64: Line 64:
</pre>
</pre>


This text overlay can be used for any information, not just from the LAN. Maybe you want to overlay the time of sunrise / sunset, or any information from an online database or website. It's limited by your imagination.
This text overlay can be used for any information, not just from the LAN. Maybe you want to overlay the time of sunrise / sunset, or any information from an online database or website.  
 
'''Possible uses of text trigger'''
* temperature
* air pressure
* humidity
* sunset/sunrise
* which alarm activated
* insert idea here


===As an External Trigger===
===As an External Trigger===

Revision as of 20:22, 16 February 2018

About

/usr/bin/zmtrigger.pl (debian location) is an optional program for Zoneminder that listens on the network for commands. Read the script for a brief description.

One way it can be used is to overlay text information from an external source (e.g. temperature sensor) onto the video feed. It can also be used as an external trigger source for cameras. By using an external trigger source, you can avoid some of the problems inherent in ZM - that of false alarms. False alarms are commonly caused when the video feed has a change come across it, such as a weather events, bugs, or the transition from daylight filter to night ir filter. An external trigger source might be one or more of a PIR, Microwave, or Ultrasonic sensor.

Note that if you have a house, or single breaker, you might want to consider using X10 for Zoneminder. This will save you the need for ethernet wiring, or setting up wifi.

Configuration

Enable it first, by going into options, config, and checking Enable Triggers.

Then

# service restart zoneminder

Verify it is running with

ps auxw | grep zmtrigger


Usage

Overlaying Text Data onto a Video Feed

After you have verified the script is running, test it is working.

Choose a monitor by monitor ID, say monitor 1, then add %Q to the monitors timestamp section.

The monitor must be in either modect, mocord, or nodect mode.

Open the video feed for monitor 1.

Then type in another terminal

telnet ipaddress 6802

in the telnet session type the following

1|show||||testingOSD

then press return.

Refer to Documentation for what this command means. A brief explanation for this is:

MonitorID # | Show text mode |||| text to put in.

You should immediately see testingOSD in place of the %Q you put in the timestamps section.

For more examples and scripts of ZMTrigger search the forums.

Example Script

Here is a script of connecting to an ipaddress that serves a value from a sensor. Wget is not as fast as possible, but this is simple and works quickly as a test.

#!/bin/bash
counter=1

while [$counter -le 10]
do
PRESSURE=`wget ipaddress -q -O -`
echo "1|show||||$PRESSURE" | telnet ipaddress 6802
sleep 4

#((counter++))
done

This text overlay can be used for any information, not just from the LAN. Maybe you want to overlay the time of sunrise / sunset, or any information from an online database or website.

Possible uses of text trigger

  • temperature
  • air pressure
  • humidity
  • sunset/sunrise
  • which alarm activated
  • insert idea here

As an External Trigger

It is possible with minor effort, to communicate with ZMTrigger.pl at the Zoneminder Server IP Address, using a microcontroller and a device that does the actual triggering. Common options would be 8-bit microcontrollers such as the Arduino Uno, the ESP8266, or an ARM based SBC such as the Raspberry Pi, Beaglebone, and others.

Types of Controllers

Uno
Arduino Uno DIP

This is up to you. If you have a wired ethernet connection available for the external sensor, then an Arduino Uno is a good choice. If you desire wireless, then an ESP8266 or ESP32 will work. An Arduino Uno will require a separate ethernet board.

Types of Sensors

You will need to decide which sensors to use. There are many options. I'll start with the common options, most likely to be used by a weekend gnulinux hacker. The first obvious options for Arduino solutions would be a PIR sensor, a Microwave sensor, or an Ultrasonic sensor.

PIR Sensors

PIR stands for Passive Infrared. These can be obtained from $4 and up online. Across auction sites from China for the cheapest, to hobbyist electronics stores for tested chinese products, and then for brand name sensors from electronics distributors like Digikey, Mouser, and Farnell. These sensors are useful, but have limitations.

  • Range is limited to 10-20 Feet. Sensitivity can be tuned.
  • Sunlight will cause false triggers. Direct OR indirect.
  • Works good in a hallway, or room where no outdoor sunlight will penetrate.

Overall, the PIR Sensors are good if you have the right environment. They are not feasible outside, but indoors, away from sunlight, they do the trick.

Microwave Sensors
HB100

Microwave sensors operate in the 10-24GHz radio bands. The 10 GHz sensors have a range of about 20-30 feet for a person, more for large vehicles (reflective metal objects). The 24GHz sensors have shorter range. There are a variety of these, from brand name, to cheap. HB100 is a common 10GHz model, though it requires an external amplifier to read the uV signal. This can be as simple as an lm386 arduino module. Other sensors have circuitry built in to output a high or low signal depending on the motion, and how sensitive you make it. These sensors are a step above the PIR in some ways, but have their own limitations.

  • Relatively short range for radio. Typically 10M, but some claim 15M. Depends on how conductive the item in motion is.
  • Can't use multiple of these, as they may interfere with each other. (need to test)
  • Items are detected greater when moving towards or away the sensor, not as much when moving across its field of sight.

Why don't I make a radio sensor that goes longer than 10M?

It's been done. But they can't be used (unless you have money enough to FCC test them). While It is possible to make FMCW radars from components and transmit in the public/unlicensed ICM bands such as 5.8GHz, you need a amateur radio license to operate them outside of testing. If you don't have an amateur radio license, then you can only use FCC certified transmitting radios. Not affordable or practical for the average hacker. You are stuck with the cheap stuff.

Ultrasonic Sensors

I have not and will not use ultrasonic sensors, but maybe someone else has some experience they can chime in with here (no pun intended).

  • Uses high frequency sound, may disrupt animals.
Infrared Trip Sensors

It's easy to find infrared trip sensors (think a laser going from 10-50 feet across). These can be setup with a microcontroller, and if someone walks across the beam, you can activate the alarm. Some brands are Sick or Seco-larm Enforcer. If you need a real short IR (inches), off the shelf Arduino modules will work (ir photo beam detector).

  • Requires power at both ends of the laser.
  • One end must connect back to server somehow (ethernet/RF)
  • Reasonably long distance.
Other Sensors

An infinite amount of devices could be used as triggers. House alarms use reed switches on windows and doors. Laser diodes could be used across long distances. If you have the capital, then there are many off the shelf products that can be purchased.

Troubleshooting

tail -f  /var/log/zm/zmtrigger.log

Enable debug on it in the logs and set to 9. The logs that contain the /var/log/zm/ logs are the component logs in options.


MySQL server has gone away error

After following forum recommendations to use mysqltuner (see MySQL), mysqltuner told me to add wait_timeout=300 to my.cnf.

Unfortunately, ZMTrigger will disconnect every five minutes, if this is enabled. It appears that ZMTrigger will "Loading monitors" every five minutes, so you can't have a wait_timeout equal or lower than that. Otherwise the MySQL server will go away. If the wait timeout is higher, then ZMTrigger will "Loading monitors" without error.

This timeout error doesn't seem to adversely affect any other features of ZM so, a low wait_timeout may be acceptable if you don't use ZMTrigger.

The default wait timeout is 8 hours for MySQL. The solution seems to be add a wait_timeout >300, or use the default. Reference:[1]

Notes

This means you could have multiple sensors, each triggering a different location. A reed switch on a window, a laser on a door, etc... When the alarm goes off, the video feed displays the alarm that was triggered.

See Also