1
0
mirror of https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks.git synced 2025-09-09 07:30:57 +02:00
Files
Solomon S ec9f5b9ff0 PTZ Presets - go home (#1387)
* Complete rewrite of PTZpresets.sh

Rewrite PTZpresets.sh to have better PID handling and full posix compatibility.

* left and right ptz presets where flipped

* Fix creation of PID file

Overly aggressive search and replace error, switch out logger to echo so PID is written to fille.

* Use full path to jq

Use full path to jq so that it still works when called from action.cgi and api.cgi

* Create Xiaomi.pm

Updated Xiaomi.pm that includes basic PTZ presets support.

* Update zoneminder.md
2020-04-30 20:44:10 +02:00

163 lines
2.8 KiB
Perl

package ZoneMinder::Control::Xiaomi;
use 5.006;
use strict;
use warnings;
use IO::Socket::SSL;
require ZoneMinder::Base;
require ZoneMinder::Control;
our @ISA = qw(ZoneMinder::Control);
our %CamParams = ();
# ==========================================================================
#
# Xiaomi Dafang Control Protocol
#
# On ControlAddress use the format :
# USERNAME:PASSWORD@ADDRESS
# eg : root:ismart@10.0.100.1
#
# ==========================================================================
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(
ssl_opts => {
verify_hostname => 0,
SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE,
});
$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=>"https://".$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 Reboot" );
$self->sendCmd( "reboot" );
}
#Up Arrow
sub moveRelUp
{
my $self = shift;
Debug( "Move Up" );
$self->sendCmd( "motor_up" );
}
#Down Arrow
sub moveRelDown
{
my $self = shift;
Debug( "Move Down" );
$self->sendCmd( "motor_down" );
}
#Left Arrow
sub moveRelLeft
{
my $self = shift;
Debug( "Move Left" );
$self->sendCmd( "motor_left" );
}
#Right Arrow
sub moveRelRight
{
my $self = shift;
Debug( "Move Right" );
$self->sendCmd( "motor_right" );
}
#Home Button
sub presetHome
{
my $self = shift;
Debug( "Move Home" );
$self->sendCmd( "motor_PTZ&x_axis=preset&y_axis=home" );
}
1;