Control script and URL for D-Link DCS-5220B1

Post here to indicate any hardware you have used and which is known to work with ZoneMinder. Not for questions.
Post Reply
link83
Posts: 1
Joined: Thu Oct 19, 2017 4:13 pm

Control script and URL for D-Link DCS-5220B1

Post by link83 » Thu Oct 19, 2017 5:10 pm

Hello,

I recently wrote a control script for my D-Link DCS5220B1, and i though it might be a good idea to share it with people around here. I wanted to add it to the Wiki but i can't find the "register" page so i decided to release it here.

Here is the script :

Code: Select all

# ==========================================================================
#
# ZoneMinder D-Link DCS-5220B1 Control Protocol Module, $Date$, $Revision$
# Copyright (C) 2001-2008  Philip Coombes
#
# 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-5220B1 camera control
# protocol
#
package ZoneMinder::Control::DCS5220B1;

use 5.006;
use strict;
use warnings;

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

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

# ==========================================================================
#
# DCS-5220B1 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}."/cgi-bin/$cmd" );
    my $res = $self->{ua}->request($req);

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

    return( $result );
}

sub cameraReset
{
    my $self = shift;
    Debug( "Camera Reset" );
    my $cmd = "/admin/setparam.cgi?System_reset=0";
    $self->sendCmd( $cmd );
}

sub moveConUp
{
    my $self = shift;
    Debug( "Move Up" );
    my $cmd = "/viewer/camctrl.cgi?move=up";
    $self->sendCmd( $cmd );
}

sub moveConDown
{
    my $self = shift;
    Debug( "Move Down" );
    my $cmd = "/viewer/camctrl.cgi?move=down";
    $self->sendCmd( $cmd );
}

sub moveConLeft
{
    my $self = shift;
    Debug( "Move Left" );
    my $cmd = "/viewer/camctrl.cgi?move=left";
    $self->sendCmd( $cmd );
}

sub moveConRight
{
    my $self = shift;
    Debug( "Move Right" );
    my $cmd = "/viewer/camctrl.cgi?move=right";
    $self->sendCmd( $cmd );
}


sub presetHome
{
    my $self = shift;
    Debug( "Home Preset" );
    my $cmd = "/viewer/camctrl.cgi?move=home";
    $self->sendCmd( $cmd );
}

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

=head1 NAME

ZoneMinder::Database - Perl extension for blah blah blah

=head1 SYNOPSIS

  use ZoneMinder::Database;
  blah blah blah

=head1 DESCRIPTION

Stub documentation for ZoneMinder, created by h2xs. It looks like the
author of the extension was negligent enough to leave the stub
unedited.

Blah blah blah.

=head2 EXPORT

None by default.



=head1 SEE ALSO

Mention other useful documentation such as the documentation of
related modules or operating system documentation (such as man pages
in UNIX), or any relevant external documentation such as RFCs or
standards.

If you have a mailing list set up for your module, mention it here.

If you have a web site set up for your module, mention it here.

=head1 AUTHOR

Philip Coombes, E<lt>philip.coombes@zoneminder.comE<gt>

=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

Settings to use :
Control tab (on the monitor window)
  • Control address : <user>:<pwd>@<IP>:<port>
  • Return location : home
Main tab
  • Type : remote
Move
  • Can move : yes
  • Can move continuous : yes
Pan
  • Can pan
  • Has pan speed : yes
  • Min pan speed : -5
  • Max pan speed : 5
Tilt
  • Can tilt
  • Has tilt speed : yes
  • Min tilt speed : -5
  • Max tilt speed : 5
Presets tab
  • Has presets : yes
  • Num presets : 0
  • Has home presets : yes
I'm not an expert at all and created this script using an existing one and this PDF. The script probably needs some improvements but as is it is good for me (better than nothing !)


The URL setting for streaming are :
  • Source type : remote
  • Remote protocol : RTSP
  • Remote method : RTP/RTSP
  • Remote host name : <user>:<pwd>@<IP>
  • Remote host port : 554
  • Remote host path : live.sdp or live2.sdp
  • Capture width : 640
  • Capture height : 480
  • Use RTSP response media URL : yes

It all works for me on zoneminder 1.29 and 1.30.

I hope it can help.

Post Reply

Who is online

Users browsing this forum: want2see and 3 guests