2
  1. 您需要通过“调制解调器”将您的 PC 连接到固定电话。

  2. 安装 wvdial(并配置它)(并测试它是否会响起您的电话)。

  3. 然后修改zoneminder 提供的脚本 以访问调制解调器(在该页面中搜索“触发器”)。

  4. 例如在您的主目录中运行该脚本。

我还发现调制解调器,相当老式,在 Linux 中没有得到很好的支持,例如“Winmodems”(很便宜),因为它们在(Windows)软件中做低级的东西以节省硬件,因此我的旧 PC 的 PCI 调制解调器是在当前的 Linux 中不再支持,即我必须找到一个硬件驱动的调制解调器,例如“Trendnet TFM 561u”。这在我的 Mint 14 系统(2013 年 12 月)上开箱即用,显示为 /dev/ttyACM0。

#!/usr/bin/perl -w

use strict;

use lib ("/opt/zm/share/perl/5.14.2");

use ZoneMinder;

$| = 1;

# mDbgInit( "myscript", level=>0, to_log=>0, to_syslog=>0, to_term=>1 );

my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_HOST, ZM_DB_USER, ZM_DB_PASS );

my $sql = "select M.*, max(E.Id) as LastEventId from Monitors as M left join Events as E on M.Id = E.MonitorId where M.Function != 'None' group by (M.Id)";
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );

my $res = $sth->execute() or die( "Can't execute '$sql': ".$sth->errstr() );
my @monitors;
while ( my $monitor = $sth->fetchrow_hashref() ) 
{
    push( @monitors, $monitor );
}

while( 1 ) {
    foreach my $monitor ( @monitors ) {
        next if ( !zmMemVerify( $monitor ) );

        my $lei = eval {               # avoid...
            $monitor->{LastEventId};   # ...aborting
        };                             # ...this script
        warn $@ if $@;                 # ...if there is no
        if( ! $lei ) {                 # ...LastEventId
        next;                          # ...e.g. for a clean start
        }                              # ...after clearing out database.

        my $last_event_id = zmHasAlarmed( $monitor, $lei );


        if ( $last_event_id ) {
            if ( $monitor->{Name} ne "monitor-1" && $monitor->{Name} ne "monitor-2" )  {
                my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
                if ( $hour > 23 || $hour < 7 ) {
                    $monitor->{LastEventId} = $last_event_id;
                    print( "Monitor ".$monitor->{Name}." has alarmed \n" );
                    my $cmd .= "echo ";
                    $cmd .= "\"";
                    $cmd .= "Garage Alarm: ".$monitor->{Name};
                    $cmd .= "\"";
                    $cmd .=  ' | mail -s `curl ifconfig.me` myemailaddress@gmail.com';
                    system ($cmd);
                    system('wvdial');
                }
            } 
        }
    }
    sleep( 1 );
}

这是我第一次尝试(修改)Perl。会很粗糙!

第一个系统 ($cmd) 使用当前 URL 向我发送电子邮件至 myemailaddress@gmail.com(您需要自行设置才能使邮件正常工作),以防万一它最近发生了变化。

第二个系统('wvdial')响起我的电话。

如您所见,“monitor-1”和“monitor-2”被忽略。

如您所见,它在晚上 11 点之后到早上 7 点之前启用。

我的 /etc/wvdial.conf 文件类似于:-

[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Modem Type = USB Modem
Phone = 123456789
ISDN = 0
Password = <Your Password>
New PPPD = yes
Username = <Your Login Name>

Modem = /dev/ttyACM0
Baud = 460800
Dial Command = ATDT
Auto Reconnect = off
Dial Attempts = 1
4

0 回答 0