Request for help with control scripts

Forum for questions and support relating to the 1.30.x releases only.
Locked
alabamatoy
Posts: 349
Joined: Sun Jun 05, 2016 2:53 pm

Request for help with control scripts

Post by alabamatoy »

I have looked all over for some details about the interface with camera PTZ control scripts and I cannot seem to find anything which describes the variables being passed between ZM and a specific control script. I am not a competent perl programmer, so I may simply be struggling with the syntax. For example, there appears to be an object in the control script $req which is the http string to be sent to the camera. It has components ($req->uri() for example) and I cannot seem to figure out how to reference the full http command string. I also dont know how to list all of the components of the class $req, so I may be using the totally wrong variable. It appears to be a hash, but I dont seem to understand how to enumerate the hash values. Q: How do I expose the whole string being sent to the camera?

Below is the line of code I'm using to post the response from the camera $res->status_line() and my attempt to show the command string $req in the log stream, but all I get for the $req value is "HASH(0x2d0cf88)" The camera responds "200 OK" every time.

Code: Select all

Error( "Control command result: '".$res->status_line()."' for URL ".$req );
Also, some fiddling with these scripts has led me to the conclusion that if I make a change to the script file, the changed script file is not reread by the system. Apparently, I hafta close the camera monitor display, then disable the monitor (in the console) which uses it, and save that, and then re-enable the monitor and save that, then re-open the specific camera in order for the system to "see" the change made to the script file. Q: Is there an easier way to force a re-read of the control script, instead of this complex process? With my limited knowledge of perl, Im having to trial-and-error this, and its a pain to go through all that for every change to the script file.

Any help from the experts would be appreciated.
Paranoid
Posts: 129
Joined: Thu Feb 05, 2009 10:40 pm

Re: Request for help with control scripts

Post by Paranoid »

Perl Tip:
Have a look at where the perl variable is being created. You will see a line something like this:

Code: Select all

   my $req = HTTP::Request->new(GET => "http://someurl/" );
The important bit is HTTP::Request (the bit before the ->new). This tells you that the $req object is an HTTP::Request object and you can then get all the information about this object by running the following:

Code: Select all

perldoc HTTP::Request
The options passed via the zmcontrol.pl script depend upon the command (move,focus etc). The zmcontrol,pl script itself can have the following options:

Code: Select all

        --autostop          -
        --xcoord [ arg ]    - X-coord
        --ycoord [ arg ]    - Y-coord
        --speed [ arg ]     - Speed
        --step [ arg ]      -
        --panspeed [ arg ]  -
        --panstep [ arg ]   -
        --tiltspeed [ arg ] -
        --tiltstep [ arg ]  -
        --preset [ arg ]    -
Try perldoc /usr/bin/zmcontrol.pl

To get all the contents of a perl object do the following:

Code: Select all

# Somewhere near the beginning of your file
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;   # Easier to find fields
#
# Many line of code later ....
    Error Dumper $req;
Paranoid
Posts: 129
Joined: Thu Feb 05, 2009 10:40 pm

Re: Request for help with control scripts

Post by Paranoid »

alabamatoy wrote: Also, some fiddling with these scripts has led me to the conclusion that if I make a change to the script file, the changed script file is not reread by the system. Apparently, I hafta close the camera monitor display, then disable the monitor (in the console) which uses it, and save that, and then re-enable the monitor and save that, then re-open the specific camera in order for the system to "see" the change made to the script file. Q: Is there an easier way to force a re-read of the control script, instead of this complex process? With my limited knowledge of perl, Im having to trial-and-error this, and its a pain to go through all that for every change to the script file.

Any help from the experts would be appreciated.
The control script will exit after a few minutes of being idle.

Like you I don’t like waiting or having to go through all the messing about to kill it so I do the following:

In the camera capability setup enable "can wake" and then add the following to your control script:

Code: Select all

sub wake {
  exit(0);
}
Then when you have changed your script click on the "wake" button and the script should exit;
alabamatoy
Posts: 349
Joined: Sun Jun 05, 2016 2:53 pm

Re: Request for help with control scripts

Post by alabamatoy »

Thank you for the help with this, I have made substantial progress as a result. I have the camera moving and responding to the script.

Q: Is there a built-in mechanism for the control HTML to display an input text box, and pass the entered text to the control script?

The way these Amcrest cameras are designed, they want to either pan from stop to stop, or else start panning until you tell it to stop, or else pan to a specific azimuth and elevation. The code to start pan and stop pan seems very fiddly. I would like to just get rid of the compas rose of arrows and have a simple text entry for azimuth (0-360) and elevation (0-90) that would be passed to the control script. But I cannot seem to figure out how to turn that on with in the control setup.
Paranoid
Posts: 129
Joined: Thu Feb 05, 2009 10:40 pm

Re: Request for help with control scripts

Post by Paranoid »

Q: Is there a built-in mechanism for the control HTML to display an input text box, and pass the entered text to the control script?
None that I know of.

Why don't you implement Move Mapped?

With that you click directly on the image and your script gets passed the x and y coordinates. You can either use this to centre the camera on where you clicked or interpret it as an absolute pan and tilt position.

NOTE: There is a bug in the ZoneMinder web code that means that if you have the default view as "control" then when you click on the image you get a digital zoom instead of move mapped. You can get around this by switching to event view and then switching back to control view.

NOTE to developers:
The bug is in skins/classic/views/js/watch.js.php line 42

Code: Select all

var showMode = "<?php echo ($showPtzControls && !empty($control))?"control":"events" ?>";
Since $control isn't defined at this point the expression evaluates to false and showMode gets set to "events"
alabamatoy
Posts: 349
Joined: Sun Jun 05, 2016 2:53 pm

Re: Request for help with control scripts

Post by alabamatoy »

Paranoid wrote:Why don't you implement Move Mapped?"
From my read of the API, this would take a pretty robust script. I would have to ping the camera to get its existing location (az and el) then store that, then somehow calculate how much to move relative to the existing az and el and pass that to the camera. I have been unsuccessful in handling any of the output coming back from the camera.

The API documentation for these cameras https://support.amcrest.com/hc/en-us/ar ... -IP2M-841-, while extensive, has a lot of errors and stuff that just simply doesn't seem to work as the API says it should. The absolute az and el seemed far simpler.

I have also implemented the pan command, a sleep 1, and a stop command, which in effect gives you the ability to jog the thing bit by bit. This may be sufficient. Crude, but sufficient.
Paranoid
Posts: 129
Joined: Thu Feb 05, 2009 10:40 pm

Re: Request for help with control scripts

Post by Paranoid »

I think you misunderstand.

I mean using the move mapped ZoneMinder functionality to get an absolute x and y position to move to instead of having a text entry box.
For example:

Code: Select all

sub moveMap {
    my $self = shift;
    my $params = shift;

    my $xcoord = $self->getParam( $params, 'xcoord', $self->{Monitor}{Width}/2 );
    my $ycoord = $self->getParam( $params, 'ycoord', $self->{Monitor}{Height}/2 );
    # Convert xcoord into pan position 0 to 359
    my $pan = int(360 * $xcoord / $self->{Monitor}{Width});
    # Convert ycoord into tilt position 0 to 89
    my $tilt = int(90 * $ycoord / $self->{Monitor}{Height});
    # Now get the following url:
    # http://$self->{Monitor}{ControlAddress}/cgi-bin/ptz.cgi?action=start&channel=0&code=PositionABS&arg1=$pan&arg2=$tilt&arg3=0

}
In
alabamatoy
Posts: 349
Joined: Sun Jun 05, 2016 2:53 pm

Re: Request for help with control scripts

Post by alabamatoy »

OK, I have all this working. Thank you very much for your assistance!

Some observations:
--The built-in CSS for the control page is ugly - the fonts are not sized to fit on the buttons, stuff is not centered that should be etc.
--The image-map functionality works but apparently some browsers simply don't understand what do to with it and nothing gets sent back to zmcontrol. It doesn't work on my phone or my locked-down version of IE, but works fine on FF.
-- Setting a preset blows away the control screen and posts the following error to the error log: "2016-12-13 12:58:28.175732 web_js 2761 ERR Object doesn't support property or method 'getValue' " but it seems to work anyway, and sets the preset correctly.

I am writing the URL and the response received from the camera to the error log. I would like to change that to something other than ERROR in the log, is there an info or warning function?

Code: Select all

Error( "Command check: '".$res->status_line()."' for URL ".$self->{Monitor}->{ControlAddress}."/$cmd" );
Q#1: What do I change "Error" to in order to put the result in the log as info instead of an error?

Q#2: Where are the default forms of the html control page?
Locked