Wanscam HW0045 Control Module

Forum for questions and support relating to the 1.30.x releases only.
Post Reply
lselinger
Posts: 31
Joined: Fri Oct 25, 2013 9:57 pm

Wanscam HW0045 Control Module

Post by lselinger » Tue Nov 28, 2017 2:41 pm

This was a quick kick at the can to get the PTZ portion of my WansCam HW0045 outdoor camera working. Credit in comments to others' work I used. It's pretty much a verbatim copy of a couple other modules with the commands changed. I'll put more effort into it as time permits to add other features or fix the diagonal movement (currently not working). For now, PTZ is working and so is setting and reading presets (16 on this camera).

Code: Select all

# ==========================================================================
#
# ZoneMinder Wanscam HW0045 IP Control Module, $Date: 2017-11-28$, $Revision: 0001 $
# This control module combines parts from FI8620_Y2k.pm as well 
# as (primarily) SPP1802SWPTZ.pm on Nov 28 2017 by Lonny Selinger
# Changes made
#       - Copied SPP1802SWPTZ.pm to WanscamHW0045.pm
#       - modified to control a Wanscam HW0045 Outdoor PTZ Camera
# 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.
#

package MyAgent;

use base 'LWP::UserAgent';


package ZoneMinder::Control::WanscamHW0045;
 
use 5.006;
use strict;
use warnings;
 
require ZoneMinder::Base;
require ZoneMinder::Control;
 
our @ISA = qw(ZoneMinder::Control);
 
our $VERSION = $ZoneMinder::Base::VERSION;
 
 
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 );
        my $logindetails = "";
        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" );
}
our $stop_command;
 
sub open
{
        my $self = shift;
 
        $self->loadMonitor();
 
        $self->{ua} = MyAgent->new;
        $self->{ua}->agent( "ZoneMinder Control Agent/" );
 
        $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});
        print "$req\n";
        my $res = $self->{ua}->request($req);
 
        if ( $res->is_success )
        {
                $result = !undef;
        }
        else
        {
                Error( "Error really, REALLY check failed:'".$res->status_line()."'" );
                Error ("Cmd:".$cmd);
        }
 
        return( $result );
}
 
sub reset
{
        my $self = shift;
        Debug( "Camera Reset" );
        my $cmd = "reboot.cgi?";
        $self->sendCmd( $cmd );
}


#Up Arrow
sub moveConUp
{
        my $self = shift;
        Debug( "Move Up" );
        my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=up";
        $self->sendCmd( $cmd );
        $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
}
 
#Down Arrow
sub moveConDown
{
        my $self = shift;
        Debug( "Move Down" );
        my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=down";
        $self->sendCmd( $cmd );
}
 
#Left Arrow
sub moveConLeft
{
        my $self = shift;
        Debug( "Move Left" );
        my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=left";
        $self->sendCmd( $cmd );
        $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
}
 
#Right Arrow
sub moveConRight
{
        my $self = shift;
        Debug( "Move Right" );
        my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=right";
        $self->sendCmd( $cmd );
        $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
}
 
#Diagonally Up Right Arrow
sub moveConUpRight
{
        my $self = shift;
        Debug( "Move Diagonally Up Right" );
        foreach my $dir ("up","right") {
                my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=$dir";
                $self->sendCmd( $cmd );
                $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
        }
}
 
#Diagonally Down Right Arrow
sub moveConDownRight
{
        my $self = shift;
        Debug( "Move Diagonally Down Right" );
        foreach my $dir ("down","right") {
                my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=$dir";
                $self->sendCmd( $cmd );
                $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
        }
}
 
#Diagonally Up Left Arrow
sub moveConUpLeft
{
        my $self = shift;
        Debug( "Move Diagonally Up Left" );
        foreach my $dir ("up","left") {
                my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=$dir";
                $self->sendCmd( $cmd );
                $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
        }
}
 
#Diagonally Down Left Arrow
sub moveConDownLeft
{
        my $self = shift;
        Debug( "Move Diagonally Down Left" );
        foreach my $dir ("down","left") {
                my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=$dir";
                $self->sendCmd( $cmd );
                $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
        }
}
 
#Stop
sub moveStop
{
        my $self = shift;
        Debug( "Move Stop" );
        my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=stop";
        $self->sendCmd( $cmd );
}

sub autoStop
{
        my $self = shift;
        my $autostop = shift;
        if( $autostop ) {
                Debug( "Auto Stop" );
                usleep( $autostop );
                my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=stop";
                $self->sendCmd( $cmd );
        }
}
 
#Move Camera to Home Position
sub presetHome
{
        my $self = shift;
        Debug( "Home Preset" );
        my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=home";
        $self->sendCmd( $cmd );
}
 
#Set preset
sub presetSet
{
    my $self = shift;
    my $params = shift;
    my $preset = $self->getParam( $params, 'preset' );
    my $presetCmd = "cgi-bin/hi3510/preset.cgi?-act=set&-status=1&-number=$preset";
    Debug( "Set Preset $preset with cmd $presetCmd" );
    my $cmd = $presetCmd;
    $self->sendCmd( $cmd );
}
 
#Goto preset
sub presetGoto
{
    my $self = shift;
    my $params = shift;
    my $preset = $self->getParam( $params, 'preset' );
    my $presetCmd = "cgi-bin/hi3510/preset.cgi?-act=goto&-status=1&-number=$preset";

    Debug( "Set Preset $preset with cmd $presetCmd" );
    my $cmd = $presetCmd;
    $self->sendCmd( $cmd );
}
 
#Turn IR on
sub wake
{
        my $self = shift;
        Debug( "Wake - IR on" );
        my $cmd = "cgi-bin/hi3510/param.cgi?cmd=setinfrared&-infraredstat=open";
        $self->sendCmd( $cmd );
}
 
#Turn IR off
sub sleep
{
        my $self = shift;
        Debug( "Sleep - IR off" );
        my $cmd = "cgi-bin/hi3510/param.cgi?cmd=setinfrared&-infraredstat=close";
        $self->sendCmd( $cmd );
}


# Zoom Control "In"
sub zoomConTele
{
    my $self = shift;
    my $params = shift;
    Debug( "Zoom Tele" );
    my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=zoomin";
    $self->sendCmd( $cmd );
    my $autostop = $self->getParam( $params, 'autostop', 0 );
    if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
    {
        usleep( $self->{Monitor}->{AutoStopTimeout} );
    $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=zoomin";
    $self->sendCmd( $cmd );
    }
}

# Zoom Control "Out"
sub zoomConWide
{
    my $self = shift;
    my $params = shift;
    Debug( "Zoom Wide" );
    my $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=zoomout";
    $self->sendCmd( $cmd );
    my $autostop = $self->getParam( $params, 'autostop', 0 );
    if ( $autostop && $self->{Monitor}->{AutoStopTimeout} )
    {
        usleep( $self->{Monitor}->{AutoStopTimeout} );
    $cmd = "cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=zoomout";
    $self->sendCmd( $cmd );
    }
}
 
1;
__END__

=head1 WANSCAMHW0045

ZoneMinder::Database - Perl extension for Wanscam HW0045 Outdoor PTZ IP Camera

=head1 SYNOPSIS

Control script for Wanscam HW0045 Outdoor PTZ IP Camera. 

=head1 DESCRIPTION

For set up, Select WansCam HW0045 as the Control Type. Leave the Control Device Blank
and in the Control Address, use the format user:pass@camera_ip:port

=head2 EXPORT

None by default.



=head1 SEE ALSO

=head1 AUTHOR

Lonny Selinger, Email: <lt>lonny.selinger(at)gmail(dot)com<gt>
Based on the work mostly in SPP1802SWPTZ.pm and partly from FI8620_Y2k.pm with
credit to their respective contributors.

=head1 COPYRIGHT AND LICENSE

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

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests