Linksys WVC-210 PTZ working

Post here to indicate any hardware you have used and which is known to work with ZoneMinder. Not for questions.
Post Reply
skydreamer
Posts: 17
Joined: Thu Apr 09, 2009 1:02 am

Linksys WVC-210 PTZ working

Post by skydreamer »

The control file is still a work in progress but does the job. I am waiting for the cgi map mode and the stop command to finish the script.
Continuous and relative moves are operational, and so are the presets.

I had a look at the GPL licensed firmware code and am sure that the camera can do map mode but it may not be available through the cgi in its current firmware 1.0

The camera has a nasty habit of going blurry when overexposed by reflected sunshine and takes 5 minutes to recover.

# ==========================================================================
#
# ZoneMinder iLinksys WVC-210 Control Protocol Module, $Date: 2009-04-06, $Revision: 001 $
# Copyright (C) 2008 Peter K (pklinux@SPAMiol.ie)
#
# 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 Linksys WVC-210 Pan and Tilt Webcam
#

package ZoneMinder::Control::WVC210;

use 5.006;
#use strict;
use warnings;

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

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

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

# ==========================================================================
#
# Linksys WVC-210 Control Protocol
#
# ==========================================================================

use ZoneMinder::Debug 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/".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" );

print( "http://$address/$cmd\n" );
my $req = HTTP::Request->new( GET=>"http://".$self->{Monitor}->{ControlAddress}."$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 = "/pt/ptctrl.cgi?mv=H";
$self->sendCmd( $cmd );
}

sub moveConUp
{
my $self = shift;
Debug( "Move Up" );
my $cmd = "/pt/ptctrl.cgi?mv=U,5";
$self->sendCmd( $cmd );
}

sub moveConDown
{
my $self = shift;
Debug( "Move Down" );
my $cmd = "/pt/ptctrl.cgi?mv=D,5";
$self->sendCmd( $cmd );
}

sub moveConLeft
{
my $self = shift;
Debug( "Move Left" );
my $cmd = "/pt/ptctrl.cgi?mv=L,5";
$self->sendCmd( $cmd );
}

sub moveConRight
{
my $self = shift;
Debug( "Move Right" );
my $cmd = "/pt/ptctrl.cgi?mv=R,5";
$self->sendCmd( $cmd );
}

sub moveConUpRight
{
my $self = shift;
Debug( "Move Up/Right" );
my $cmd = "/pt/ptctrl.cgi?mv=UR,5";
$self->sendCmd( $cmd );
}

sub moveConUpLeft
{
my $self = shift;
Debug( "Move Up/Left" );
my $cmd = "/pt/ptctrl.cgi?mv=UL,5";
$self->sendCmd( $cmd );
}

sub moveConDownRight
{
my $self = shift;
Debug( "Move Down/Right" );
my $cmd = "/pt/ptctrl.cgi?mv=DR,5";
$self->sendCmd( $cmd );
}

sub moveConDownLeft
{
my $self = shift;
Debug( "Move Down/Left" );
my $cmd = "/pt/ptctrl.cgi?mv=DL,5";
$self->sendCmd( $cmd );
}

sub moveRelUp
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'tiltstep' );
Debug( "Step Up $step" );
my $cmd = "/pt/ptctrl.cgi?position=0,$step";
$self->sendCmd( $cmd );
}

sub moveRelDown
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'tiltstep' );
Debug( "Step Down $step" );
my $cmd = "/pt/ptctrl.cgi?position=0,-$step";
$self->sendCmd( $cmd );
}

sub moveRelLeft
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'panstep' );
Debug( "Step Left $step" );
my $cmd = "/pt/ptctrl.cgi?position=-$step,0";
$self->sendCmd( $cmd );
}

sub moveRelRight
{
my $self = shift;
my $params = shift;
my $step = $self->getParam( $params, 'panstep' );
Debug( "Step Right $step" );
my $cmd = "/pt/ptctrl.cgi?position=$step,0";
$self->sendCmd( $cmd );
}

# Diagonal movements were hacked as zmcontrol.pl does not pass panstep and tiltstep

sub moveRelUpRight
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panspeed' );
my $tiltstep = $self->getParam( $params, 'tiltspeed' );
Debug( "Step Up/Right $tiltstep/$panstep" );
my $cmd = "/pt/ptctrl.cgi?position=$panstep,$tiltstep";
$self->sendCmd( $cmd );
}

sub moveRelUpLeft
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panspeed' );
my $tiltstep = $self->getParam( $params, 'tiltspeed' );
Debug( "Step Up/Left $tiltstep/$panstep" );
my $cmd = "/pt/ptctrl.cgi?position=-$panstep,$tiltstep";
$self->sendCmd( $cmd );
}

sub moveRelDownRight
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panspeed' );
my $tiltstep = $self->getParam( $params, 'tiltspeed' );
Debug( "Step Down/Right $tiltstep/$panstep" );
my $cmd = "/pt/ptctrl.cgi?position=$panstep,-$tiltstep";
$self->sendCmd( $cmd );
}

sub moveRelDownLeft
{
my $self = shift;
my $params = shift;
my $panstep = $self->getParam( $params, 'panspeed' );
my $tiltstep = $self->getParam( $params, 'tiltspeed' );
Debug( "Step Down/Left $tiltstep/$panstep" );
my $cmd = "/pt/ptctrl.cgi?position=-$panstep,-$tiltstep";
$self->sendCmd( $cmd );
}


sub moveMap
{
my $self = shift;
my $params = shift;
my $xcoord = $self->getParam( $params, 'xcoord' );
my $ycoord = $self->getParam( $params, 'ycoord' );
Debug( "Move Map to $xcoord,$ycoord" );
my $cmd = "/pt/ptctrl.cgi?mv=$xcoord,$ycoord";
$self->sendCmd( $cmd );
}

sub moveStop
{
my $self = shift;
Debug( "Stop Movement" );
my $cmd = "/pt/ptctrl.cgi";
$self->sendCmd( $cmd );
}

sub presetSet
{
my $self = shift;
my $params = shift;
my $preset = $self->getParam( $params, 'preset' );
Debug( "Set Preset $preset" );
my $cmd = "/pt/ptctrl.cgi?preset=save,$preset";
$self->sendCmd( $cmd );
}

sub presetGoto
{
my $self = shift;
my $params = shift;
my $preset = $self->getParam( $params, 'preset' );
Debug( "Goto Preset $preset" );
my $cmd = "/pt/ptctrl.cgi?preset=move,$preset";
$self->sendCmd( $cmd );
}

sub presetHome
{
my $self = shift;
Debug( "Home Preset" );
my $cmd = "/pt/ptctrl.cgi?preset=move,103";
$self->sendCmd( $cmd );
}

1;
__END__

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

=head1 NAME

ZoneMinder::Database - Perl extension for WVC-210

=head1 SYNOPSIS

use ZoneMinder::Database;


=head1 DESCRIPTION

Stub documentation for ZoneMinder, created by PK.

Linksys WVC-210

=head2 EXPORT

None by default.



=head1 SEE ALSO

See Linksys Website for details.

=head1 AUTHOR

Peter K

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2008-2009 Peter K

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.
skydreamer
Posts: 17
Joined: Thu Apr 09, 2009 1:02 am

Post by skydreamer »

And the settings are:

Type: Remote
Protocol: WVC210
Can Reset

Can Move
Can Move Diagonally
Can Move Absolute... this is pending the TS response
Can Move Relative

Can Pan
Min Pan Range: -135
Max Pan Range: +135
Min Pan Step: 0
Max Pan Step: 250
Has Pan Speed
Min Pan Speed:0
Max Pan Speed:250

Can Tilt
Min Tilt Range: -45
Max Tilt Range: 90
Min Tilt Step: 0
Max Tilt Step: 250
Has Tilt Speed
Min Tilt Speed: 0
Max Tilt Speed: 250

Has Presets
Num Presets: 9
Has Home Preset
Can Set Presets


The rest of the values should be left at default.

The mjpeg stream is accessible via /img/video.mjpeg and it runs at 15fps at 640x480.

The camera does not allow speed control but since there is a bug? in the parent script the WVC210.pl does not get pan and tilt, only the speed which is used for diagonal movement.

Clicking on any point of the image while in the PTZ mode makes the camera move that point more less to the centre.

I am not using the continuous mode. The subs were left in it from the WVC200 script that was published elsewhere in this forum and I used it as a proof of concept before discovering the relative moves

I guess the camera should be able to track the movement too? It is only one tick box away :-)

I hope you will find the above useful,

Peter
User avatar
henriquejf
Posts: 77
Joined: Tue Feb 10, 2009 12:01 pm
Location: Brazil

Wvc210 Ptz to stream mjpeg to zm

Post by henriquejf »

congratulations for the posts, im sure theyre gonna be widely useful !

could you be so kind to just tell me, apart from the ptz control, if the mjpeg streaming worked "natively" with zm, or did you have to hack anything for the Wvc210 Ptz to talk to zm ? i have seen some posts that left those doubt to me... i have seen users trying to use its mpeg compressor, and i think that wont be the best bet ....

tks for any attention, regards !

:: EDIT :: skydreamer kindly pm'ed me that the mjpeg streaming worked out of the box with zm in his opinion, what i think may be useful to others; tks man !
-----------------------
Henrique Barbosa
Consultant
Juiz de Fora, MG - Brazil
marrandy
Posts: 13
Joined: Fri Aug 26, 2005 6:06 pm

Post by marrandy »

PClinuxOS - 2009 with zm from synaptic
Linux localhost 2.6.26.8.tex3 #1 SMP Mon Jan 12 04:33:38 CST 2009 i686 Intel(R) Core(TM)2 Duo CPU P8400 @ 2.26GHz GNU/Linux
zm v1.23.2

Hmm...I tried connecting to one at work yesterday and all I saw was a broken screen image.

Maybe a setting needs changing.

I'll recheck in an hour or so when I get back in.

ADD: They are WVC200V1.1 & WVC210V1

This is a new ZM install so I haven't tested with any other camera's.

That's all I have at work.

I'm also trying a sony-SNC-DF40N

OK - going to http://192.168.168.24/image I can see the camera video in the linux firefox web browser. I can't get it to display in zoneminder. Any pointers ?
marrandy
Posts: 13
Joined: Fri Aug 26, 2005 6:06 pm

Post by marrandy »

I think there are network issues here. This is a re-occuring issue, but I'm not allowed to fix them. One day, I will get access/control to sort the network out.
What happens is the linksys cameras randomly turn Red and the picture is then black. Putting them, temporarily on a local test switch solves those issues.
So my result, thanks to a lot of other peoples work is...

WVC200 & 210 - remote host path = /img/video.mjpeg

Sony SNC-DF40N - remote host path = /image

I haven't upgraded to the latest for the PTZ. Something to look at when I have more time.

Many thanks to the contributors to this project.
marrandy
Posts: 13
Joined: Fri Aug 26, 2005 6:06 pm

Post by marrandy »

marrandy wrote:.Putting them, temporarily on a local test switch solves those issues...

Famous last words. I'm having lots of the same random issues.

Just lost my previous post.

I'll try the V1.24.2 and then am going to Axis cameras.
PRDR
Posts: 17
Joined: Sun Nov 26, 2006 11:16 pm

Re: Linksys WVC-210 PTZ working

Post by PRDR »

skydreamer wrote:The control file is still a work in progress but does the job. I am waiting for the cgi map mode and the stop command to finish the script.
Continuous and relative moves are operational, and so are the presets.

....


=head1 SEE ALSO

See Linksys Website for details.

=head1 AUTHOR

Peter K

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2008-2009 Peter K

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.
This sounds great, but I would like to know how to use it... Sorry everyone for my dire ignorance:
How do I use this code? I have zm-v1.23.3 installed, because that's the version that's in ubuntu 9.04 reps.

Do I have to create a file containing the code lines in a particular folder?
An then, what do I enter under "Control Device and Control Address" at Monitor-->Control?

I already created a "WVC210" control (Control Type ... Edit) with the entries described in another post above.

Thanks in advance for the reply, or for a pointer where I might learn more about this... I would love to be able to use this camera's PTZ functionality with ZM.
PRDR
Posts: 17
Joined: Sun Nov 26, 2006 11:16 pm

Post by PRDR »

Well, I finally made it work by following the directions given for another camera (airlink 777W) in another thread.

Just in case somebody is interested, you have to copy the PTZ code posted at the beginning of this thread, and paste it into a file called WVC210.pm, which, if you are using the ZM setup of the ubuntu packages, should end up being stored in the /usr/share/perl5/ZoneMinder/Control/ folder.
After that it is necessary to go to the "Control" tab at the setup window of your cam, define the cam as Controllable, and follow the "Edit" link next to "Control Type".
Then "Add a New Control" in the "Control Capabilities" window, following the directions given above in this thread. You can give this control any name, like "Linksys WVC210" for instance.
When you are done saving your new control, you should refresh the little window containing your "Control" tab, and select your new "Linksys WVC210" as the "Control Type".
The "Control Adress" field should be like username:password@cam.ip.address (like the "Remote Host Name" at the "Source" tab). I have my cam setup for http port 80, so I do not know exactly what to do if you have defined a different one, perhaps you could try something like username:password@cam.ip.address:port

Anyways, it is working, although with huge delays. Perhaps it is that my PC is a bit old and the load of reading the mjpeg stream is too high. Something similar seems to have happened with an airlink camera, as soon as I went back to read jpeg stills from the camera instead of the mjpg stream, the PTZ controls started working like a charm.

Anybody knows the address that should be given for capturing jpg stills instead of the mjpeg stream for the WVC210?
EDIT: Never mind, I found this in another thread (for the WVC200, actually): /img/snapshot.cgi. It works just fine. ZM captures the stills from there instead of the mjpeg stream, and the PTZ controls are running smoothly from ZM now.


Thanks a million for all the great work involved in making this work!
daveharris
Posts: 25
Joined: Mon Oct 26, 2009 2:47 pm

Post by daveharris »

I've now had some sucess in getting the control working.

I'm running ZM v 1.23.3 and after discoving the foscam.pl file was case sensitive (changed package ZoneMinder::Control::Foscam; to package ZoneMinder::Control::foscam; on the first line) i got these errors:

Nov 3 10:32:18 ZoneMinder zmcontrol[26314]: INF [Starting control server 1/foscam]
Nov 3 10:32:18 ZoneMinder zmcontrol[26317]: INF [Control server 1/foscam starting at 09/11/03 10:32:18]
Nov 3 10:32:19 ZoneMinder zmcontrol[26317]: FAT [Can't access Up member of object of class ZoneMinder::Control::foscam]

So, i renamed on of the functions from 'moveConUp' to 'Up' and saved it (no restart required) and it worked.

So now im thnking i need to get the lastest version of ZM on that box to use the newer moveConUp commands etc? I also fancy doing some styling to the interface but that can wait for now.

I will upgrade and see how that goes.

Fingers corssed.

DAVE.
Post Reply