Skip to content

Instantly share code, notes, and snippets.

@ablakely
Last active April 16, 2020 20:57
Show Gist options
  • Save ablakely/fd04d8a3a350671d2b95a13f87fc3d06 to your computer and use it in GitHub Desktop.
Save ablakely/fd04d8a3a350671d2b95a13f87fc3d06 to your computer and use it in GitHub Desktop.
AXIS 214 CGI Control Script for motion
#!/usr/bin/perl -w
# camctrl.pl: AXIS 214 CGI Control Script
#
# USAGE: For use with motion-project.github.io generic tracking function
# If it tracks something like trees,
# the solution I found is to set the limits for ptz in the camera settings
#
# Copyright 2020 (C) Ephasic Software
# Written by Aaron Blakely <aaron@ephasic.org>
use strict;
use warnings;
my $LOCKED = 0;
# SCRIPT CONFIG #
my $USER = "camera auth user"; # basic http auth user
my $PASS = "password"; # basic http auth password
my $HOST = "10.0.0.12; # host/ip of camera
# CAMERA CONFIG - Set for AXIS 214 PTZ #
my $CAMID = 1; # Camera ID
my $OFFSET1 = 2/8; # OFFSET 1 (for left and up)
my $OFFSET2 = 5/8; # OFFSET 2 (for right and down)
my $BASE_URL = "/axis-cgi/com/ptz.cgi";
my $LOCKFILE = "/tmp/camctrl.lock";
# Modify these functions to fit your camera!
sub wget {
my ($query) = @_;
system "wget -O /tmp/camctrlwget.log --http-user=$USER --http-password=$PASS 'http://$HOST$BASE_URL?camera=$CAMID&$query'";
}
sub movecam {
my ($direction) = @_;
system "touch $LOCKFILE";
if ($direction eq "left") {
wget("move=left&zoom=400");
} elsif ($direction eq "right") {
wget("move=right&zoom=400")
} elsif ($direction eq "up") {
wget("move=up&rzoom=30");
} elsif ($direction eq "down") {
wget("move=down&rzoom=30");
} elsif ($direction eq "home") {
wget("zoom=0");
sleep 2;
wget("move=home");
}
$LOCKED = 1;
}
# END SCRIPT CONFIG #
if (-e $LOCKFILE) {
die "[ANTI FLOOD] Exiting...\n";
}
if ($ENV{TRACK_ACTION} eq "center") {
movecam("home");
} elsif ($ENV{TRACK_ACTION} eq "move") {
if ($ENV{TRACK_CENT_X} < $ENV{TRACK_IMGS_WIDTH} * $OFFSET1) {
print STDERR "$ENV{TRACK_CENT_X} < ".$ENV{TRACK_IMGS_WIDTH} * $OFFSET1."\n";
movecam("left");
} elsif ($ENV{TRACK_CENT_X} > $ENV{TRACK_IMGS_WIDTH} * $OFFSET2) {
print STDERR "$ENV{TRACK_CENT_X} > ".$ENV{TRACK_IMGS_WIDTH} * $OFFSET2."\n";
movecam("right");
} elsif ($ENV{TRACK_CENT_Y} < $ENV{TRACK_IMGS_HEIGHT} * $OFFSET1) {
movecam("up");
} elsif ($ENV{TRACK_CENT_Y} > $ENV{TRACK_IMGS_HEIGHT} * $OFFSET2) {
movecam("down");
}
}
if ($LOCKED == 1) {
sleep 1;
unlink $LOCKFILE or warn $!;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment