DCS-5222l pan/tilt control script

Forum for questions and support relating to the 1.28.x releases only.
Post Reply
make77
Posts: 1
Joined: Wed Dec 30, 2015 5:57 am

DCS-5222l pan/tilt control script

Post by make77 » Wed Dec 30, 2015 6:13 am

hi,

i'm actually totally new to ZoneMinder, so please accept my apology if i ask any beginner questions.
i successfully setup my DCS-5222L and I'm able to receive the video stream.
what I'm not able to get up and running is the pan/tilt controls.

i tried so far to modify this script https://wiki.zoneminder.com/TV-IP672PI_Control_Script but cause of my not existing programming/scripting knowledge i was not able to figure out what exactly i need to amend.
i actually tried to remove/change the authentications since this is submitted together with the link/IP of the camera.
the control link for the camera i found here in WIKI :

move to preset #0: /cgi/ptdc.cgi?command=goto_preset_position&presetId=0
move to home position: /cgi/ptdc.cgi?command=go_home
pan left by 10 units: /cgi/ptdc.cgi?command=set_relative_pos&posX=-10&posY=0
pan right by 10 units: /cgi/ptdc.cgi?command=set_relative_pos&posX=10&posY=0
tilt up by 10 units: /cgi/ptdc.cgi?command=set_relative_pos&posX=0&posY=10
tilt down by 10 units: /cgi/ptdc.cgi?command=set_relative_pos&posX=0&posY=-10
auto pan: /cgi/ptdc.cgi?command=pan_patrol
auto pan/tilt between user configured positions: /cgi/ptdc.cgi?command=user_patrol
stop auto: /cgi/ptdc.cgi?command=stop

i appreciate any help in regards to get the control script working
thanks a lot in advance for al replies

Matt

i modified the attached script but is unfortunately not working. its not doing anything and there is nothing in the ZM log as well.

Code: Select all

# =========================================================================r
#
# ZoneMinder D-Link DCS-5020L IP Control Protocol Module, $Date: $, $Revision: $
# Copyright (C) 2013 Art Scheel
#
# 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ==========================================================================
#
# This module contains the implementation of the D-Link DCS-5020L IP camera control
# protocol. 
#
package ZoneMinder::Control::DCS5020L;

use 5.006;
use strict;
use warnings;

require ZoneMinder::Base;
require ZoneMinder::Control;

our @ISA = qw(ZoneMinder::Control);

our $VERSION = $ZoneMinder::Base::VERSION;

# ==========================================================================
#
# D-Link DCS-5020L 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( POST=>"http://".$self->{Monitor}->{ControlAddress}."/cgi/ptdc.cgi?command=" );
    $req->content($cmd);
    my $res = $self->{ua}->request($req);

    if ( $res->is_success )
    {
        $result = !undef;
    }
    else
    {
        Error( "Error check failed: '".$res->status_line()."'" );
    }

    return( $result );
}

sub sendCmd2
{
    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} );

    my $res = $self->{ua}->request($req);

    if ($res->is_success )
    {
        $result = !undef;
    }
    else
    {
        Error( "Error check failed:'".$res->status_line()."'" );
    }

    return( $result );
}

sub move
{
    my $self = shift;
    my $dir = shift;
    my $panSteps = shift;
    my $tiltSteps = shift;

    my $cmd = "set_relative_pos&posX=$panSteps&posY=$tiltSteps";
    $self->sendCmd( $cmd );
}

sub moveRelUpLeft
{
    my $self = shift;
    Debug( "Move Up Left" );
    $self->move(-3, 3);
}

sub moveRelUp
{
    my $self = shift;
    Debug( "Move Up" );
    $self->move(0, 3);
}

sub moveRelUpRight
{
    my $self = shift;
    Debug( "Move Up Right" );
    $self->move(3, 3);
}

sub moveRelLeft
{
    my $self = shift;
    Debug( "Move Left" );
    $self->move(-3, 0);
}

sub moveRelRight
{
    my $self = shift;
    Debug( "Move Right" );
    $self->move(3, 0);
}

sub moveRelDownLeft
{
    my $self = shift;
    Debug( "Move Down Left" );
    $self->move(-3, -3);
}

sub moveRelDown
{
    my $self = shift;
    Debug( "Move Down" );
    $self->move(0, -3);
}

sub moveRelDownRight
{
    my $self = shift;
    Debug( "Move Down Right" );
    $self->move(3, -3);
}

# moves the camera to center on the point that the user clicked on in the video image. 
# This isn't extremely accurate but good enough for most purposes 
sub moveMap
{
    # if the camera moves too much or too little, try increasing or decreasing this value
    my $f = 11;

    my $self = shift;
    my $params = shift;
    my $xcoord = $self->getParam( $params, 'xcoord' );
    my $ycoord = $self->getParam( $params, 'ycoord' );

    my $hor = $xcoord * 100 / $self->{Monitor}->{Width};
    my $ver = $ycoord * 100 / $self->{Monitor}->{Height};
   
    my $direction;
    my $horSteps;
    my $verSteps;
    if ($hor < 50 && $ver < 50) {
        # up left
        $horSteps = (50 - $hor) / $f;
        $verSteps = (50 - $ver) / $f;
        $direction = 0;
    } elsif ($hor >= 50 && $ver < 50) {
        # up right
        $horSteps = ($hor - 50) / $f;
        $verSteps = (50 - $ver) / $f;
        $direction = 2;
    } elsif ($hor < 50 && $ver >= 50) {
        # down left
        $horSteps = (50 - $hor) / $f;
        $verSteps = ($ver - 50) / $f;
        $direction = 6;
    } elsif ($hor >= 50 && $ver >= 50) {
        # down right
        $horSteps = ($hor - 50) / $f;
        $verSteps = ($ver - 50) / $f;
        $direction = 8;
    }
    my $v = int($verSteps + .5);
    my $h = int($horSteps + .5);
    Debug( "Move Map to $xcoord,$ycoord, hor=$h, ver=$v with direction $direction" );
    $self->move( $direction, $h, $v );
}

# this clear function works, but should probably be disabled because 
# it isn't possible to set presets yet. 
sub presetClear
{
    my $self = shift;
    my $params = shift;
    my $preset = $self->getParam( $params, 'preset' );
    Debug( "Clear Preset $preset" );
    my $cmd = "ClearPosition=$preset";
    $self->sendCmd( $cmd );
}

# not working yet
sub presetSet
{
    my $self = shift;
    my $params = shift;
    my $preset = $self->getParam( $params, 'preset' );
    Debug( "Set Preset $preset" );
    # TODO need to first get current position $horPos and $verPos
    #my $cmd = "PanTiltHorizontal=$horPos&PanTiltVertical=$verPos&SetName=$preset&SetPosition=$preset";
    #$self->sendCmd( $cmd );
}

sub presetGoto
{
    my $self = shift;
    my $params = shift;
    my $preset = $self->getParam( $params, 'preset' );
    Debug( "Goto Preset $preset" );
    my $cmd = "PanTiltPresetPositionMove=$preset";
    $self->sendCmd( $cmd );
}

sub presetHome
{
    my $self = shift;
    Debug( "Home Preset" );
    my $cmd = "go_home";
    $self->sendCmd( $cmd );
}


#  IR Controls
#
#  wake = IR on
#  sleep = IR off
#  reset = IR auto


sub wake
{
    #  force IR on  ("always night mode")

    my $self = shift;
    my $url = "/eng/admin/adv_audiovideo.cgi";
    my $cmd = "irMode=3";

    Debug("Wake -- IR on");

    $self->sendCmdPost ($url,$cmd);
}

sub sleep
{
    #  force IR off ("always day mode")

    my $self=shift;
    my $url = "/eng/admin/adv_audiovideo.cgi";
    my $cmd = "irMode=2";

    Debug("Sleep -- IR off");

    $self->sendCmdPost ($url,$cmd);
}

sub reset
{
    #  IR auto

    my $self=shift;
    my $url = "/eng/admin/adv_audiovideo.cgi";
    my $cmd = "irMode=0";

    Debug("Reset -- IR auto");

    $self->sendCmdPost ($url,$cmd);
}

1;
__END__
# Below is stub documentation for your module. You'd better edit it!

=head1 NAME

ZoneMinder::Database - Perl extension for DCS-5020L

=head1 SYNOPSIS

  use ZoneMinder::Database;
  DLINK DCS-5020L

=head1 DESCRIPTION

ZoneMinder driver for the D-Link consumer camera DCS-5020L.

=head2 EXPORT

None by default.



=head1 SEE ALSO

See if there are better instructions for the DCS-5020L at
http://www.zoneminder.com/wiki/index.php/Dlink

=head1 AUTHOR

Art Scheel <lt>ascheel (at) gmail<gt>

=head1 COPYRIGHT AND LICENSE

LGPLv3

=cut

SPapus4e
Posts: 1
Joined: Mon Jun 27, 2016 8:42 am

Re: DCS-5222l pan/tilt control script

Post by SPapus4e » Mon Jun 27, 2016 8:45 am

IP Camera Name: DCS-5222L-B1
Brand: D-Link
Firmware version: 2.13.01
Hardware version: B
MCU version: 20140207
Agent version: 2.0.20-b31
Nipca version: 1.9.5

The below mentioned is based on Network IP Camera Application Programming Interface(NIPCA-API). More CGI commands applicable on DCS-5222L are available in this document: NIPCA 1.9.1 tv-ip612xx_cgi-10.pdf. Just search for the file name.

Syntax:
http://cameraIPaddress:Port/CGI-URL?parameter=value

/common/info.cgi

/config/auto_patrol.cgi?act=go
Patrol only a single time between presets.
It seems that the camera has no permanent auto patrol (auto pan) function implemented. A script or a schedule starting this command periodically could be a resolution.

/config/auto_pan.cgi?act=go
Pan only a single time.

/config/ptz_info.cgi
/config/ptz_preset_list.cgi

/config/wlansignal.cgi
/config/wlansurvey.cgi

scorpiocs
Posts: 4
Joined: Thu Mar 09, 2017 11:26 am

Re: DCS-5222l pan/tilt control script

Post by scorpiocs » Fri Apr 28, 2017 1:40 pm

I successfully setup video also for this cam. But control still does not work. Do you have working protocol file ? How create control type for this cam ?

blaha
Posts: 2
Joined: Tue Nov 27, 2018 4:01 pm

Re: DCS-5222l pan/tilt control script

Post by blaha » Tue Nov 27, 2018 4:06 pm

Damn, me too. I bought the DCS-5222L thinking D-Link support would be as universal as Panasonic.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests