Amcrest PTZ functionality

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.
alabamatoy
Posts: 130
Joined: Sun Jun 05, 2016 2:53 pm

Amcrest PTZ functionality

Post by alabamatoy » Fri Dec 16, 2016 5:31 pm

Here is the control script: https://drive.google.com/open?id=0BytuB ... 19QY0Z4dWs

This is a control script that implements pan, tilt, zoom tele, zoom wide, goto preset and set preset IAW version 2 of the Amcrest HTTP SDK described here https://support.amcrest.com/hc/en-us/ar ... -IP2M-841-

Its just text, but it doesn't display correctly on Windows machines because of EOL character differences between Linux and M$. I think there is a more capable version of Notepad called Notepad++ which will fix this on a windows box. Instructions for implementing the script within Zoneminder (its written / tested on ZM 1.3 on Ubuntu 16.04) are at the end of the file.

If you use this script, I would appreciate some feedback, hey it works, you suck its a PoS or whatever. I would very much like to know if it works on something other than my 16.04 Ubuntu and ZM 1.3

If it works for you and you like it, please consider a small ( $10?) donation to "Care Assurance System for the Aging and Homebound of Madison County", their donation site is here: http://casamadisoncty.org/donate/

davidsmoot
Posts: 15
Joined: Tue Feb 26, 2013 2:35 am

Re: Amcrest PTZ functionality

Post by davidsmoot » Sat Dec 31, 2016 5:27 pm

Thanks for your work on this. I downloaded your .pm file and I copied it to the folder /usr/share/perl5/ZoneMinder/Control. I checked permissions and owner to match the other control files in that directory. I restarted zoneminder. I see no new control options. I think I need to edit Control.pm in the parent directory but I don't know Perl.

How do I install your script? Get me working and I'll donate to your charity.

David

alabamatoy
Posts: 130
Joined: Sun Jun 05, 2016 2:53 pm

Re: Amcrest PTZ functionality

Post by alabamatoy » Sat Dec 31, 2016 5:44 pm

Read the bottom of the script - you gotta make some changes in the monitor for each controllable camera. LMK if it works or no after making these changes to each monitor. You should not have to make any other changes.

davidsmoot
Posts: 15
Joined: Tue Feb 26, 2013 2:35 am

Re: Amcrest PTZ functionality

Post by davidsmoot » Sun Jan 01, 2017 1:15 pm

Read the script. Mostly works but I think you have one omission.

No where in your instructions in the script do you enable "Pan" capability. So I could tilt and Zoom but not pan after following the instructions. I simply checked the Pan checkbox and it appears to work with your code. I do not know if I need to change any of the sub-options on Pan or not.

I do need to mess with the timing and test with another Amcrest camera model but it appears you have a working solution. Thank you. Donation made to your charity and I forwarded the receipt to the email in your script.

David

alabamatoy
Posts: 130
Joined: Sun Jun 05, 2016 2:53 pm

Re: Amcrest PTZ functionality

Post by alabamatoy » Sun Jan 01, 2017 1:31 pm

davidsmoot wrote:Read the script. Mostly works but I think you have one omission.
Rats. Yes, it should pan, that's just my oversight on the instructions, thanks for the feedback and I will update the instructions.

WRT the timing, you can simply click the zoom+ or pan or tilt buttons on the interface several times, and it will zoom several steps in rapid succession. Zoom- always goes to full wide. I wanted to have the timing adjustable via the interface, but I couldn't figure out how to modify the default ZM control web page to accomplish that.

And CASA appreciates the donation!

User avatar
iconnor
Posts: 613
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: Amcrest PTZ functionality

Post by iconnor » Tue Jan 10, 2017 2:14 pm

Hey alabamatoy, can I assist you in getting this into ZoneMinder?

Do you have plans to do so, or can I just grab the script and make a PR in your name?

davidsmoot
Posts: 15
Joined: Tue Feb 26, 2013 2:35 am

Re: Amcrest PTZ functionality

Post by davidsmoot » Tue Jan 10, 2017 2:24 pm

I can confirm his script works and works well. I have stored presets and done PTZ on 8 cameras representing 2 models (their indoor and outdoor POE PTZ dome cameras). Preset appear to properly store on camera, they are accessible from other interfaces than Zoneminder.

David

alabamatoy
Posts: 130
Joined: Sun Jun 05, 2016 2:53 pm

Re: Amcrest PTZ functionality

Post by alabamatoy » Tue Jan 10, 2017 2:26 pm

iconnor wrote:Hey alabamatoy, can I assist you in getting this into ZoneMinder?

Do you have plans to do so, or can I just grab the script and make a PR in your name?
I do not know where to begin, so I defer entirely to your intent. The script has setup/install instructions included at the end, please reformat or whatever is necessary, or point me at a guide as to what must be done.

It will be several days before I can put any time into this, however...so I dont want to hold up your schedule with the next release.

tledford
Posts: 1
Joined: Mon Dec 26, 2016 6:59 pm

Re: Amcrest PTZ functionality

Post by tledford » Tue Jan 10, 2017 3:13 pm

Donation made, script works great.

surfshack66
Posts: 1
Joined: Fri Mar 17, 2017 5:58 pm

Re: Amcrest PTZ functionality

Post by surfshack66 » Fri Mar 17, 2017 6:02 pm

Thanks @alabamatoy. The script works great.

Any way to add functionality so that I can control the camera using the zmNinja app? Currently the control feature on the app doesn't work.

alabamatoy
Posts: 130
Joined: Sun Jun 05, 2016 2:53 pm

Re: Amcrest PTZ functionality

Post by alabamatoy » Fri Mar 17, 2017 6:06 pm

surfshack66 wrote:Any way to add functionality so that I can control the camera using the zmNinja app? Currently the control feature on the app doesn't work.
No idea, that would a research project. I have not used zmNinja, so.....

User avatar
asker
Posts: 957
Joined: Sun Mar 01, 2015 12:12 pm

Re: Amcrest PTZ functionality

Post by asker » Sat Apr 01, 2017 5:04 pm

the next release of zmNinja (1.2.42) will support this script (actually not just this script, but cameras that only support mapped move). For now zmNinja will only support up/down/left/right/diagonal movements - not the actual ability to move to an arbitrary spot that mapped move allows.
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

Gilley7997
Posts: 6
Joined: Sun Apr 02, 2017 5:36 pm

Re: Amcrest PTZ functionality

Post by Gilley7997 » Sun Apr 02, 2017 5:47 pm

So I was actually working on modifying my own script for this, and was running into a problem with a 401 Authorization Error when I was attempting the GET call from the Perl Module.

In Googling to try to figure this out, I came across this script, and I figured I would download it and give it a shot. Exact same issue. The odd part is if I copy the URL call out of the Info Logs in ZoneMinder and put this directly in a WebBrowser I get an OK code back with no 401 Issue.

This was a Brand New Camera, so I updated it to the latest Firmware that was released on 3/22/2017 before attempting to work with the scripts. This is the Version Data off the Camera:

Software Version
2.420.AC00.17.R, Build Date: 2017-03-22
WEB Version
3.2.1.434383
ONVIF Version
2.42

This is the log that this script creates for a move Right:
Camera control command FAILED: '401 Unauthorized' for URL user:password@10.10.10.92/cgi-bin/ptz.cgi?action=start&code=Right&channel=0&arg1=0&arg2=1&arg3=0

If I copy this out, add http:// to the front of it and paste it back into chrome, the motion starts with no issue.

So was hoping I could verify with someone who has this working what software version they are running and if they are experiencing the same issue, I am hoping but also not hoping that it is a Firmware issue and Not a ZoneMinder Issue.
Last edited by Gilley7997 on Mon Apr 03, 2017 1:19 am, edited 1 time in total.

alabamatoy
Posts: 130
Joined: Sun Jun 05, 2016 2:53 pm

Re: Amcrest PTZ functionality

Post by alabamatoy » Sun Apr 02, 2017 9:39 pm

Gilley7997 wrote:This is the log that this script creates for a move Right:
Camera control command FAILED: '401 Unauthorized' for URL user:password@10.10.10.92/cgi-bin/ptz.cgi?action=stop&code=Right&channel=0&arg1=0&arg2=1&arg3=0

If I copy this out, add http:// to the front of it and paste it back into chrome, the motion starts with no issue.
How can that be, you are telling the camera to STOP motion, not start?!? If the URL had "action=start" then perhaps, but with it directing a stop, something else is wrong.

Is the code actually sending the HTTP:// or HTTPS://, a correctly formatted get (it may be a PUT, I can't recall from memory)? If its only sending the string you have quoted, then that may be the problem.

I would grab a copy of wireshark and look at what is actually being sent to the camera by the code. That should tell you what the camera is actually receiving. If its actually sending the correct protocol and text, then you have got something else wrong.

PS, you dont want to be doing what you are doing over http of course, your login/pw are in the clear. If its going from your ZM node on your LAN to your camera on your LAN and never leaving the LAN, then its OK. But its bad practice anyway.

Gilley7997
Posts: 6
Joined: Sun Apr 02, 2017 5:36 pm

Re: Amcrest PTZ functionality

Post by Gilley7997 » Mon Apr 03, 2017 1:25 am

You got to this before I had a chance to edit it. Your code calls both functions in the same call (as did mine), and I just copy and pasted the last log error, it actually fails the same way for both the start and stop action.

That is the direct code from your Module not mine, and it is using http, and I agree with you that definitely shouldn't ever leave my LAN, and it does not,
It is actually isolated on a specific segment of my LAN at home.

I had not changed the Module you created in ANY way, but I am receiving this error. Have you tested this lately on a Amcrest CAM. If so what Firmware is it using? Thanks for replying, just can't understand why out of the Zoneminder call, it's unauthorized, but from a Webbrowser it's fine.

I have gone over both your code and my own and can't find where the issue would lie in the code itself, so I was wondering if anyone was running this on this latest firmware as well.

This is the relevant line of code that sets the command and sends the commmand and also generates the log.

Code: Select all

    #section of code that formats the API Call
    $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&code=Right&channel=0&arg1=0&arg2=1&arg3=0' );
    usleep (500);
    $self->sendCmd( 'cgi-bin/ptz.cgi?action=stop&code=Right&channel=0&arg1=0&arg2=1&arg3=0' );
    
    #relevant section from sendCmd Function:
    my $req = HTTP::Request->new( GET=>"http://".$self->{Monitor}->{ControlAddress}."/$cmd" );
    my $res = $self->{ua}->request($req);

    #Section that is generating the log entry I pasted above:
     if ( $res->is_success )
    {
        $result = !undef;
        # Command to camera appears successful, write Info item to log
        Info( "Camera control: '".$res->status_line()."' for URL ".$self->{Monitor}->{ControlAddress}."/$cmd" );
    }
    else
    {
        Error( "Camera control command FAILED: '".$res->status_line()."' for URL ".$self->{Monitor}->{ControlAddress}."/$cmd" );
    }
This is the dump from wireshark, the credentials were correct prior to being blacked out as well as the host name and port. The camera is listenting and responding as the very next packet is the acknowledgement and then the returned 401 Unauthorized message
Wireshark.png
Wireshark.png (14.61 KiB) Viewed 4905 times

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests