Zoneminder: control module for Vstarcam C7824WIP
Perl module to control the Vstarcam C7824WIP with Zoneminder.
C7824WIP.pm:
# ==========================================================================
#
# ZoneMinder Vstarcam C7824WIP IP Control Protocol Module, $Date: 2017-01-15 01:17:54 +0100 (Wed, 04 Nov 2009) $, $Revision: 1 $
# Copyright (C) 2017 Mentor (http://www.internauta37.altervista.org)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# ==========================================================================
#
# This module is based on WanscamHW0025.pm
#
# ==========================================================================
#
# This module contains the implementation of the Vstarcam C7824WIP IP camera control
# protocol
#
package ZoneMinder::Control::C7824WIP;
use 5.006;
use strict;
use warnings;
require ZoneMinder::Base;
require ZoneMinder::Control;
our @ISA = qw(ZoneMinder::Control);
# ==========================================================================
#
# Vstarcam C7824WIP IP Control Protocol
#
# ==========================================================================
use ZoneMinder::Logger qw(:all);
use ZoneMinder::Config qw(:all);
use Time::HiRes qw( usleep );
sub new
{
my $class = shift;
my $id = shift;
my $self = ZoneMinder::Control->new( $id );
bless( $self, $class );
srand( time() );
return $self;
}
our $AUTOLOAD;
sub AUTOLOAD
{
my $self = shift;
my $class = ref($self) || croak( "$self not object" );
my $name = $AUTOLOAD;
$name =~ s/.*://;
if ( exists($self->{$name}) )
{
return( $self->{$name} );
}
Fatal( "Can't access $name member of object of class $class" );
}
sub open
{
my $self = shift;
$self->loadMonitor();
use LWP::UserAgent;
$self->{ua} = LWP::UserAgent->new;
$self->{ua}->agent( "ZoneMinder Control Agent/".ZoneMinder::Base::ZM_VERSION );
$self->{state} = 'open';
}
sub close
{
my $self = shift;
$self->{state} = 'closed';
}
sub printMsg
{
my $self = shift;
my $msg = shift;
my $msg_len = length($msg);
Debug( $msg."[".$msg_len."]" );
}
sub sendCmd
{
my $self = shift;
my $cmd = shift;
my $result = undef;
printMsg( $cmd, "Tx" );
my $req = HTTP::Request->new( GET=>"http://".$self->{Monitor}->{ControlAddress}."/$cmd".$self->{Monitor}->{ControlDevice} );
Info( "http://".$self->{Monitor}->{ControlAddress}."/$cmd".$self->{Monitor}->{ControlDevice} );
my $res = $self->{ua}->request($req);
if ( $res->is_success )
{
$result = !undef;
}
else
{
Error( "Error check failed: '".$res->status_line()."'" );
}
return( $result );
}
sub reset
{
my $self = shift;
Debug( "Camera Reset" );
my $cmd = "reboot.cgi?";
$self->sendCmd( $cmd );
}
#Up Arrow
sub Up
{
my $self = shift;
Debug( "Move Up" );
my $cmd = "decoder_control.cgi?command=0&onestep=1&";
$self->sendCmd( $cmd );
}
#Down Arrow
sub Down
{
my $self = shift;
Debug( "Move Down" );
my $cmd = "decoder_control.cgi?command=2&onestep=1&";
$self->sendCmd( $cmd );
}
#Left Arrow
sub Left
{
my $self = shift;
Debug( "Move Left" );
my $cmd = "decoder_control.cgi?command=4&onestep=1&";
$self->sendCmd( $cmd );
}
#Right Arrow
sub Right
{
my $self = shift;
Debug( "Move Right" );
my $cmd = "decoder_control.cgi?command=6&onestep=1&";
$self->sendCmd( $cmd );
}
#Diagonally Up Right Arrow
sub UpRight
{
my $self = shift;
Debug( "Move Diagonally Up Right" );
my $cmd = "decoder_control.cgi?command=91&onestep=1&";
$self->sendCmd( $cmd );
}
#Diagonally Down Right Arrow
sub DownRight
{
my $self = shift;
Debug( "Move Diagonally Down Right" );
my $cmd = "decoder_control.cgi?command=93&onestep=1&";
$self->sendCmd( $cmd );
}
#Diagonally Up Left Arrow
sub UpLeft
{
my $self = shift;
Debug( "Move Diagonally Up Left" );
my $cmd = "decoder_control.cgi?command=90&onestep=1&";
$self->sendCmd( $cmd );
}
#Diagonally Down Left Arrow
sub DownLeft
{
my $self = shift;
Debug( "Move Diagonally Down Left" );
my $cmd = "decoder_control.cgi?command=92&onestep=1&";
$self->sendCmd( $cmd );
}
#Up Arrow
sub moveConUp
{
my $self = shift;
my $params = shift;
Debug( "Move Up" );
my $cmd = "decoder_control.cgi?command=0&onestep=0&";
$self->sendCmd( $cmd );
my $autostop = $self->getParam( $params, 'autostop', 0 );
if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
{
usleep( $self->{Monitor}->{AutoStopTimeout} );
$self->moveStop( $params );
}
}
#Down Arrow
sub moveConDown
{
my $self = shift;
my $params = shift;
Debug( "Move Down" );
my $cmd = "decoder_control.cgi?command=2&onestep=0&";
$self->sendCmd( $cmd );
my $autostop = $self->getParam( $params, 'autostop', 0 );
if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
{
usleep( $self->{Monitor}->{AutoStopTimeout} );
$self->moveStop( $params );
}
}
#Left Arrow
sub moveConLeft
{
my $self = shift;
my $params = shift;
Debug( "Move Left" );
my $cmd = "decoder_control.cgi?command=4&onestep=0&";
$self->sendCmd( $cmd );
my $autostop = $self->getParam( $params, 'autostop', 0 );
if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
{
usleep( $self->{Monitor}->{AutoStopTimeout} );
$self->moveStop( $params );
}
}
#Right Arrow
sub moveConRight
{
my $self = shift;
my $params = shift;
Debug( "Move Right" );
my $cmd = "decoder_control.cgi?command=6&onestep=0&";
$self->sendCmd( $cmd );
my $autostop = $self->getParam( $params, 'autostop', 0 );
if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
{
usleep( $self->{Monitor}->{AutoStopTimeout} );
$self->moveStop( $params );
}
}
#Diagonally Up Right Arrow
sub moveConUpRight
{
my $self = shift;
my $params = shift;
Debug( "Move Diagonally Up Right" );
my $cmd = "decoder_control.cgi?command=91&onestep=0&";
$self->sendCmd( $cmd );
my $autostop = $self->getParam( $params, 'autostop', 0 );
if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
{
usleep( $self->{Monitor}->{AutoStopTimeout} );
$self->moveStop( $params );
}
}
#Diagonally Down Right Arrow
sub moveConDownRight
{
my $self = shift;
my $params = shift;
Debug( "Move Diagonally Down Right" );
my $cmd = "decoder_control.cgi?command=93&onestep=0&";
$self->sendCmd( $cmd );
my $autostop = $self->getParam( $params, 'autostop', 0 );
if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
{
usleep( $self->{Monitor}->{AutoStopTimeout} );
$self->moveStop( $params );
}
}
#Diagonally Up Left Arrow
sub moveConUpLeft
{
my $self = shift;
my $params = shift;
Debug( "Move Diagonally Up Left" );
my $cmd = "decoder_control.cgi?command=90&onestep=0&";
$self->sendCmd( $cmd );
my $autostop = $self->getParam( $params, 'autostop', 0 );
if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
{
usleep( $self->{Monitor}->{AutoStopTimeout} );
$self->moveStop( $params );
}
}
#Diagonally Down Left Arrow
sub moveConDownLeft
{
my $self = shift;
my $params = shift;
Debug( "Move Diagonally Down Left" );
my $cmd = "decoder_control.cgi?command=92&onestep=0&";
$self->sendCmd( $cmd );
my $autostop = $self->getParam( $params, 'autostop', 0 );
if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
{
usleep( $self->{Monitor}->{AutoStopTimeout} );
$self->moveStop( $params );
}
}
#Stop
sub moveStop
{
my $self = shift;
Debug( "Move Stop" );
my $cmd = "decoder_control.cgi?command=1&onestep=1&";
$self->sendCmd( $cmd );
}
#Move Camera to Home Position
sub presetHome
{
my $self = shift;
Debug( "Home Preset" );
my $cmd = "decoder_control.cgi?command=25&onestep=0&";
$self->sendCmd( $cmd );
}
#Set preset
sub presetSet
{
my $self = shift;
my $params = shift;
my $preset = $self->getParam( $params, 'preset' );
my $presetCmd = 30 + (($preset-1)*2);
Debug( "Set Preset $preset with cmd $presetCmd" );
my $cmd = "decoder_control.cgi?command=$presetCmd&onestep=0&sit=$presetCmd&";
$self->sendCmd( $cmd );
}
#Goto preset
sub presetGoto
{
my $self = shift;
my $params = shift;
my $preset = $self->getParam( $params, 'preset' );
my $presetCmd = 31 + (($preset-1)*2);
Debug( "Goto Preset $preset with cmd $presetCmd" );
my $cmd = "decoder_control.cgi?command=$presetCmd&onestep=0&sit=$presetCmd&";
$self->sendCmd( $cmd );
}
#Turn IR on
sub wake
{
my $self = shift;
Debug( "Wake - IR on" );
my $cmd = "camera_control.cgi?param=14&value=1&";
$self->sendCmd( $cmd );
}
#Turn IR off
sub sleep
{
my $self = shift;
Debug( "Sleep - IR off" );
my $cmd = "camera_control.cgi?param=14&value=0&";
$self->sendCmd( $cmd );
}
1;
__END__
=head1 NAME
ZoneMinder::Database - Perl extension for Vstarcam C7824WIP
=head1 SYNOPSIS
use ZoneMinder::Control::C7824WIP
Control module for for Vstarcam C7824WIP
=head1 DESCRIPTION
This module contains the implementation of the Vstarcam C7824WIP IP
camera control protocol.
=head2 EXPORT
None by default.
=head1 SEE ALSO
You can find the documentation at:
http://www.internauta37.altervista.org/en/zoneminder-control-module-vstarcam-c7824wip
=head1 AUTHOR
Philip Coombes, <[email protected]>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2001-2008 Philip Coombes
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.3 or,
at your option, any later version of Perl 5 you may have available.
=cut
The module C7824WIP.pm have to be put in the path:
/usr/share/perl5/ZoneMinder/Control
with permissions 644.
In Zoneminder Options>System>OPT_CONTROL √ have to be enabled.
The monitor for the Vstarcam C7824WIP can be configured as follow:
Main
Name: NAME_YOU_WANT
Source Type: Remote
Function: Modect
Enabled: √
Source
Remote Protocol: HTTP
Remote Method: Simple
Remote Host Name: IP
Remote Host Port: 81 (81 is the default port of Vstarcam C7824WIP)
Remote Host Path: /videostream.cgi?user=admin&pwd=888888 (888888 is the default password of Vstarcam C7824WIP)
Target colorspace: 24 bit colour
Capture Width (pixels): 640
Capture Width (pixels): 360
Control
Controllable: √
Control Type: Edit
Add New Control
Main
Name: C7824WIP
Type: Remote
Protocol: C7824WIP
Can Wake: √
Can Sleep: √
Can Reset: √
Move
Can Move: √
Can Move Diagonally: √
Can Move Continuous: √
Pan
Can Pan: √
Tilt
Can Tilt: √
Presets
Has presets: √
Num Presets: 16
Has Home Preset: √
Can Set Presets: √
Control Type: C7824WIP
Control Device: loginuse=admin&loginpas=888888
Control Address: IP:PORT (ex. 192.168.1.100:81)
The Vstarcam C7824WIP can also be configured to use the ffmpeg for the video stream as follow:
Main stream: rtsp://admin:PWD@IP:10554/udp/av0_0 1280*720
Secondary stream: rtsp://admin:PWD@IP:10554/udp/av0_1 640*360
The third stream: rtsp://admin:PWD@IP:10554/udp/av0_2 320*180
Secondary stream + Audio: rtsp://admin:PWD@IP:10554/udp/av1_1 640*360
Section:
1 comments
Re: Zoneminder: control module for Vstarcam C7824WIP
Grazie! I looked for days for a solution, and then I came across your script. It works perfectly!
Add new comment