-
Notifications
You must be signed in to change notification settings - Fork 4
/
cam_watch.pl
47 lines (38 loc) · 1.48 KB
/
cam_watch.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl
use Fcntl qw(LOCK_EX LOCK_NB);
use File::NFSLock;
# Try to get an exclusive lock on myself.
my $lock = File::NFSLock->new($0, LOCK_EX|LOCK_NB);
die "$0 is already running!\n" unless $lock;
while (1) {
$a= `/usr/bin/curl -s 'http://192.168.0.25:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=xxx&pwd=xxx' ` ;
($status)=($a=~/motionDetectAlarm>(\d)<\//);
($status_rec)=($a=~/record>(\d)<\//);
($cam)=($a=~/http%3A%2F%2F(.+)\.myfoscam/);
#print "test: $cam $status\n";
if (($status==1)&&(-e "/var/tmp/alarm_on.$cam")) {
#motion sensor
print "alarm off";
unlink "/var/tmp/alarm_on.$cam";
`/usr/bin/curl -s "http://192.168.0.24:8080/json.htm?type=command¶m=switchlight&idx=8&switchcmd=Off"`;
};
if (($status==2)&&(! -e "/var/tmp/alarm_on.$cam")) {
#motion sensor
print "alarm on";
system("touch /var/tmp/alarm_on.$cam");
`/usr/bin/curl -s "http://192.168.0.24:8080/json.htm?type=command¶m=switchlight&idx=8&switchcmd=On"`;
}
if (($status_rec==0)&&(-e "/var/tmp/rec_on.$cam")) {
#PIR1_Rec
print "rec off";
unlink "/var/tmp/rec_on.$cam";
`/usr/bin/curl -s "http://192.168.0.24:8080/json.htm?type=command¶m=switchlight&idx=11&switchcmd=Off"`;
};
if (($status_rec>0)&&(! -e "/var/tmp/rec_on.$cam")) {
#PIR1_Rec
print "rec on";
system("touch /var/tmp/rec_on.$cam");
`/usr/bin/curl -s "http://192.168.0.24:8080/json.htm?type=command¶m=switchlight&idx=11&switchcmd=On"`;
}
sleep(10);
}