iPhone - iPCamera software PTZ

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
Daedilus
Posts: 5
Joined: Sat Jun 09, 2018 7:41 pm

iPhone - iPCamera software PTZ

Post by Daedilus »

Hello Everyone. Been a bit of a lurker here and wish to contribute.

For those whom have an old iphone laying around there is a piece of inexpensive software that I use for some mobile IP Cameras.
https://itunes.apple.com/ca/app/ipcamer ... 12928?mt=8

And if you go the webserver on the phone there are a few options like rotate the picture, flip horizontal / vertical, change the stream quality, change the camera from front facing to main camera, lock the focus, white balance and exposure. So now I've made them available through the control schema.

For the Control settings
Control Address: <user>:<password>@<ip address>:80
In the app you can set a username password and it displays its IP address.

Settings you need are
Control Type: FFMPEG
Protocol: IPCAMIOS

Move
Can Move: Check
Can Move Continuous: Check

Pan
Can Pan: Check
Put 0 for all values.

Tilt
Can Tilt: Check
Put 0 for all values

Focus
Can Focus: Check
Can Focus Absolute: Check
Put 0 for all values.

White
Can White Balance: Check
Can White Bal. Absolute: Check
Put 0 for all values.

Iris
Can Iris: Check
Can Iris Absolute: Check
Put 0 for all values.

Presets
Has Presets: Check
Num Presets: 0
Has Home Preset: Check

Script is named IPCAMIOS.pm and is as follows.
For those whom haven't done this before it is placed in the below directory of your ZM server:

/usr/share/perl5/ZoneMinder/Control

Code: Select all

# ==========================================================================
#
# ZoneMinder iPhone Control Protocol Module, $Date: 2018-07-15 00:20:00 +0000 $, $Revision: 0003 $
# Copyright (C) 2001-2008  Philip Coombes
#
# Modified for iPhone ipcamera for IOS BY PETER ZARGLIS n 2018-06-09 13:45:00
# 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 iPhone ipcamera for IOS
# control protocol.
#
# ==========================================================================
package ZoneMinder::Control::IPCAMIOS;

use 5.006;
use strict;
use warnings;

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

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

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

# ==========================================================================
#
# iPhone ipcamera for IOS Protocol
#
# ==========================================================================

use ZoneMinder::Logger qw(:all);
use ZoneMinder::Config qw(:all);
use Time::HiRes qw( usleep );

my $loopfactor=100000;

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($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" );


    $self->{state} = 'open';
}

sub close
{
    my $self = shift;
    $self->{state} = 'closed';
}

sub sendCmd
{
    my $self = shift;
    my $cmd = shift;
    my $result = undef;
    my $req = HTTP::Request->new( GET=>"http://".$self->{Monitor}->{ControlAddress}."/$cmd" );
    my $res = $self->{ua}->request($req);
    if ( $res->is_success )
    {
        $result = $res->decoded_content;
    }
    else
    {
        Error( "Error check failed: '".$res->status_line()."'" );
    }
    return( $result );
}
sub getDisplayAttr
{
    my $self = shift;
    my $param = shift;
    my $cmdget = "parameters?";
    my $resp = $self->sendCmd( $cmdget );
    my @fields = split(',',$resp);
    my $response=$fields[$param];
    my @buffer=split(':',$response);
    my $response2=$buffer[1];
    return ($response2);
}

sub sleep
{

}
# Flip image vertically -> Horz -> off
sub moveConUp
{
    my $self = shift;
    my $params = shift;
    Debug( "Flip Image" );
    my $dvalue=$self->getDisplayAttr(3);
    if ( $dvalue == 2 )
    {
    $dvalue=0;
    my $cmd = "parameters?flip=$dvalue";
    $self->sendCmd( $cmd );
    }
    else
    {
    $dvalue=$dvalue+1;
    my $cmd = "parameters?flip=$dvalue";
    $self->sendCmd( $cmd );
    }
}
# Change camera (front facing or back)
sub moveConDown
{
   	my $self = shift;
    my $params = shift;
    Debug( "Change Camera" );
    my $dvalue=$self->getDisplayAttr(7);
    if ( $dvalue == 0 )
    {
    my $cmd = "parameters?camera=1";
    $self->sendCmd( $cmd );
    }
	else
	{
	my $cmd = "parameters?camera=0";
    $self->sendCmd( $cmd );
	}
}
# Picture Orientation Clockwise
sub moveConRight
{
	my $self = shift;
	my $params = shift;
	Debug( "Orientation" );
	my $dvalue=$self->getDisplayAttr(10);
	if ( $dvalue == 1 )
	{
	$dvalue=4;
	my $cmd = "parameters?rotation=$dvalue";
	$self->sendCmd( $cmd );
	}
	else 
	{	
	$dvalue=$dvalue-1;
	my $cmd = "parameters?rotation=$dvalue";
	$self->sendCmd( $cmd );
	}
}
# Picture Orientation Anti-Clockwise
sub moveConLeft
{
    my $self = shift;
    my $params = shift;
    Debug( "Orientation" );
    my $dvalue=$self->getDisplayAttr(10);
    if ( $dvalue == 4 )
	{
	$dvalue=1;
	my $cmd = "parameters?rotation=$dvalue";
	$self->sendCmd( $cmd );
	}
	else
	{
	$dvalue=$dvalue+1;
	my $cmd = "parameters?rotation=$dvalue";
	$self->sendCmd( $cmd );
	}
}

# presetHome is used to turn off Torch, unlock Focus, unlock Exposure, unlock white-balance, rotation, image flipping
# Just basically reset all the little variables and set it to medium quality
# Rotation = 0 means it will autoselect using built in detection
sub presetHome
{
	my $self = shift;
	Debug( "Home Preset" );
	my $cmd = "parameters?torch=0&focus=0&wb=0&exposure=0&rotation=0&flip=0&quality=0.5";
	$self->sendCmd( $cmd );
}

sub focusAbsNear
# Focus Un/Lock
{
	my $self = shift;
	my $params = shift;
	Debug( "Focus Un/Lock" );
	my $dvalue=$self->getDisplayAttr(2);
	if ( $dvalue == 0 )
	{
	my $cmd = "parameters?focus=1";
	$self->sendCmd( $cmd );
	}
	else
	{
	my $cmd = "parameters?focus=0";
	$self->sendCmd( $cmd );
	}
}

sub focusAbsFar
# Exposure Un/Lock
{
	my $self = shift;
	my $params = shift;
	Debug( "Exposure Un/Lock" );
	my $dvalue=$self->getDisplayAttr(11);
	if ( $dvalue == 0 )
	{
	my $cmd = "parameters?exposure=1";
	$self->sendCmd( $cmd );
	}
	else
	{
	my $cmd = "parameters?exposure=0";
	$self->sendCmd( $cmd );
	}
}
# Increase stream Quality (from 0 to 10)
sub irisAbsOpen
{
	my $self = shift;
	my $params = shift;
	Debug( "Quality" );
	my $dvalue=$self->getDisplayAttr(8);
	if ( $dvalue < 1 )
	{
	$dvalue=$dvalue+0.1;
	my $cmd = "parameters?quality=$dvalue";
	$self->sendCmd( $cmd );
	}
}

# Decrease stream Quality (from 10 to 0)
sub irisAbsClose
{
	my $self = shift;
	my $params = shift;
	Debug( "Quality" );
	my $dvalue=$self->getDisplayAttr(8);
	if ( $dvalue > 0 )
	{
	$dvalue=$dvalue-0.1;
	my $cmd = "parameters?quality=$dvalue";
	$self->sendCmd( $cmd );
	}
}
# White Balance Un/Lock
sub whiteAbsIn
{
	my $self = shift;
	my $params = shift;
	Debug( "White Balance" );
	my $dvalue=$self->getDisplayAttr(9);
	if ( $dvalue == 0 )
	{
	my $cmd = "parameters?wb=1";
	$self->sendCmd( $cmd );
	}
	else
	{
	my $cmd = "parameters?wb=0";
	$self->sendCmd( $cmd );
	}
}

# Torch control on/off
sub whiteAbsOut
{
	my $self = shift;
	my $params = shift;
	Debug( "Torch" );
	my $dvalue=$self->getDisplayAttr(5);
	if ( $dvalue == 0 )
	{
	my $cmd = "parameters?torch=1";
	$self->sendCmd( $cmd );
	}
	else
	{
	my $cmd = "parameters?torch=0";
	$self->sendCmd( $cmd );
	}
}

1;
Last edited by Daedilus on Mon Jul 16, 2018 4:41 pm, edited 1 time in total.
Daedilus
Posts: 5
Joined: Sat Jun 09, 2018 7:41 pm

Re: iPhone - iPCamera software

Post by Daedilus »

The controls are as follows

Focus Near: Locks / Unlocks the Focus
Focus Far: Locks / Unlock the Exposure
White In: Locks / Unlocks the White Balance
White Out: Turns the Light(Torch) On/Off
Iris Open: Increase Stream Quality (From 0 to 10 by increments of 1)
Iris Close: Decrease Steam Quality (From 10 to 0 by increments of 1)

Move Up: Flip the Image (Vert -> Horz -> Off)
Move Down: Toggle Main Camera / Secondary Camera

Move Left: Rotate Counter/Anti Clockwise the video
Move Right: Rotate Clockwise the video.
(Note: Doing so will upset the capture width and height you have set in the source tab for the monitor you will have to exchange these values if you wish to keep the setting)

Home button will turn off Torch, unlock Focus, unlock Exposure, unlock white-balance, rotation, image flipping and set the quality to 50%

Hope this works out for everyone
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: iPhone - iPCamera software PTZ

Post by asker »

Very nice. Can you please do a PR so its merged into ZoneMinder?
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Daedilus
Posts: 5
Joined: Sat Jun 09, 2018 7:41 pm

Re: iPhone - iPCamera software PTZ

Post by Daedilus »

Not sure how to do that.
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: iPhone - iPCamera software PTZ

Post by asker »

I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Daedilus
Posts: 5
Joined: Sat Jun 09, 2018 7:41 pm

Re: iPhone - iPCamera software PTZ

Post by Daedilus »

I think that's it.
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: iPhone - iPCamera software PTZ

Post by asker »

Thanks for the PR! I look forward to using it
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Post Reply