Skip to content

Instantly share code, notes, and snippets.

@edwork
Forked from joshstrange/Xiaomi.pm
Last active December 1, 2018 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwork/3564a711805889e0a2d53cd074807712 to your computer and use it in GitHub Desktop.
Save edwork/3564a711805889e0a2d53cd074807712 to your computer and use it in GitHub Desktop.
Control script for Sannce Cameras (work in progress)
package ZoneMinder::Control::Sannce;
use 5.006;
use strict;
use warnings;
require ZoneMinder::Base;
require ZoneMinder::Control;
our @ISA = qw(ZoneMinder::Control);
our %CamParams = ();
# ==========================================================================
#
# Sannce 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 );
my $logindetails = "";
bless( $self, $class );
srand( time() );
return $self;
}
our $AUTOLOAD;
sub AUTOLOAD
{
my $self = shift;
my $class = ref( ) || 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/action.cgi?cmd=$cmd" );
my $res = $self->{ua}->request($req);
if ( $res->is_success )
{
$result = !undef;
}
else
{
Error( "Error check failed:'".$res->status_line()."'" );
}
return( $result );
}
# Reset the Camera
sub reset
{
my $self = shift;
Debug( "Camera Reset" );
$self->sendCmd( "reboot" );
}
#Up Arrow
sub moveRelUp
{
my $self = shift;
Debug( "Move Up" );
my $cmd = "decoder_control.cgi?command=0";
$self->sendCmd( "motor_up" );
}
#Down Arrow
sub moveRelDown
{
my $self = shift;
Debug( "Move Down" );
my $cmd = "decoder_control.cgi?command=2";
$self->sendCmd( "motor_down" );
}
#Left Arrow
sub moveRelLeft
{
my $self = shift;
Debug( "Move Left" );
my $cmd = "decoder_control.cgi?command=4";
$self->sendCmd( "motor_left" );
}
#Right Arrow
sub moveRelRight
{
my $self = shift;
Debug( "Move Right" );
my $cmd = "decoder_control.cgi?command=6";
$self->sendCmd( "motor_right" );
}
1;
@edwork
Copy link
Author

edwork commented Dec 1, 2018

Profile for Sannce cameras in Zoneminder for PTZ control.

WIP - This is still mostly code for Xiomi Dafang Cameras!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment