New Amcrest firmware breaks PTZ

Forum for questions and support relating to the 1.30.x releases only.
tcg
Posts: 40
Joined: Fri Jan 13, 2012 3:41 pm

New Amcrest firmware breaks PTZ

Post by tcg » Tue Mar 20, 2018 3:00 pm

I received a new Amcrest IP2M-841E yesterday with an updated firmware. I already had one of these cameras with a slightly older firmware working with ZoneMinder. I can't get the PTZ to work with the new camera's firmware (2.520.AC00.18.R, Build Date: 2017-06-29). I can send commands via wget on the command line and it works. For example:

Code: Select all

wget -q 'http://username:password@hostname/cgi-bin/ptz.cgi?action=start&code=Right&channel=0&arg1=1&arg2=1&arg3=0
I haven't managed to get it to work with curl though. The ZM PTZ controls are failing but I do get a little more information:

Code: Select all

Camera control command FAILED: '401 Unauthorized' for URL username:password@hostname/cgi-bin/ptz.cgi?action=start&code=Left&channel=0&arg1=0&arg2=1&arg3=0
This is based on the amcrest781.pm script posted by alabamatoy a while back. It's been working fine until this firmware update. One of the entries in the Amcrest firmware ChangeLog was this rather vague message:

Code: Select all

10. Security improvements.
Any advice on debugging why this is failing?
Chris

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

Re: New Amcrest firmware breaks PTZ

Post by alabamatoy » Wed Mar 21, 2018 2:40 pm

I think you may be experiencing this:
viewtopic.php?f=9&t=25606&start=15#p99740

I have not tried to troubleshoot it, because I cannot replicate the issue on my current setup, and I am not going to shoot myself in the foot by upgrading to the new firmware!

Please post back what you find out about this. It may require a wireshark capture to get to the true circumstances.

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

Re: New Amcrest firmware breaks PTZ

Post by alabamatoy » Wed Mar 21, 2018 2:43 pm

Also, there is a whole bunch of asking and complaining about this on the Amcrest forum. See https://amcrest.com/forum/search.php?ke ... entication

AFAICT, there has been no acknowledgement by Amcrest that the problem even exists.

I suspect there is a way around this in CURL, but I havent been able to figure it out.

tcg
Posts: 40
Joined: Fri Jan 13, 2012 3:41 pm

Re: New Amcrest firmware breaks PTZ

Post by tcg » Wed Mar 28, 2018 12:58 am

I have it working for my IP2M-841EB cameras now with firmware 2.520.AC00.18.R, Build Date: 2017-06-29. I've attached an updated version of your amcrest781.pm file. This one is called amcrest841.pm. I had to change a few things to get it to work.

First, I had to change it to use digest authentication. This requires knowing the realm of the login. On my cameras, this is a string like "Login to
AMC0147447WBBX5UHF" where the last part is the camera serial number. Obviously, this has to change for each individual camera so I used the ControlDevice field in the camera's setup to hold the serial number string for the realm. Also, digest authentication apparently requires the port number in the hostname portion so the ControlAddress field now needs to look something like this:

Code: Select all

username:password@hostname:port
See attached screenshot. Since ControlAddress needs to follow this format and there is the requirement for the realm, I removed the code that assumed admin:admin as the default credentials as it won't work without the realm anyway.

Finally, I noticed that the UserAgent has to be reset between each individual call to the camera. This might be an authentication token problem that somebody else might know how to straighten out. But for now, each call, reinitializes the UserAgent. I added a couple of subroutines to handle this. Without this, the first sendCmd will work but after that you'll get authentication problems again.

Improvements to my changes are welcome. It's been a while since I did Perl. Too many scripting languages bouncing around in my head. :)
Attachments
amcrest841.pm.txt
Rename this to amcrest841.pm
(12.06 KiB) Downloaded 251 times
control.png
control.png (18.93 KiB) Viewed 3847 times
Chris

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

Re: New Amcrest firmware breaks PTZ

Post by alabamatoy » Wed Mar 28, 2018 5:45 pm

I cross-posted this to the other thread. Thanks for fixing! I am interested to see if this works with my older firmware.

Knnniggett, can this be added to distro?

skluthe
Posts: 1
Joined: Thu May 03, 2018 12:04 am

Re: New Amcrest firmware breaks PTZ

Post by skluthe » Thu May 03, 2018 12:06 am

tcg wrote:
Wed Mar 28, 2018 12:58 am
I have it working for my IP2M-841EB cameras now with firmware 2.520.AC00.18.R, Build Date: 2017-06-29. I've attached an updated version of your amcrest781.pm file. This one is called amcrest841.pm. I had to change a few things to get it to work.

First, I had to change it to use digest authentication. This requires knowing the realm of the login. On my cameras, this is a string like "Login to
AMC0147447WBBX5UHF" where the last part is the camera serial number. Obviously, this has to change for each individual camera so I used the ControlDevice field in the camera's setup to hold the serial number string for the realm. Also, digest authentication apparently requires the port number in the hostname portion so the ControlAddress field now needs to look something like this:

Code: Select all

username:password@hostname:port
See attached screenshot. Since ControlAddress needs to follow this format and there is the requirement for the realm, I removed the code that assumed admin:admin as the default credentials as it won't work without the realm anyway.

Finally, I noticed that the UserAgent has to be reset between each individual call to the camera. This might be an authentication token problem that somebody else might know how to straighten out. But for now, each call, reinitializes the UserAgent. I added a couple of subroutines to handle this. Without this, the first sendCmd will work but after that you'll get authentication problems again.

Improvements to my changes are welcome. It's been a while since I did Perl. Too many scripting languages bouncing around in my head. :)
Looks as though this one still isn't working for me. I downloaded your file straight from this site using wget from my zoneminder server and them renamed it to amcrest-working.pm and It's giving me this error:

Control response was status = undefined
message = /usr/bin/zmcontrol.pl --command=Up --id=3=>

Any ideas or anything else I can provide to help with troubleshooting?

tcg
Posts: 40
Joined: Fri Jan 13, 2012 3:41 pm

Re: New Amcrest firmware breaks PTZ

Post by tcg » Tue May 08, 2018 12:13 pm

The error is caused from ZM trying to execute the Up() function in the control script. It's apparently not finding it which kind of tells me that the camera's control tab might not be set up correctly. After copying the script to the right place, you have to then go to your camera's "Control" tab and associate the script with the camera. Next to "Control Type" click "Edit" and make sure you've set the script up properly. Have you done that?
Chris

chris_19
Posts: 10
Joined: Mon Feb 04, 2019 1:49 pm

Re: New Amcrest firmware breaks PTZ

Post by chris_19 » Wed Feb 06, 2019 7:31 pm

@tcg

Any chance you could post the results of the query below (with the id value adjusted to match your record) from your IPM2? (Note: I have changed only the name of the control module. Otherwise, the code is an exact duplicate of that which you posted above.)

I have a few things right and my 853EW will PT, but some stuff apparently wrong as it won't Z. I see things such as this in the log:

Code: Select all

Feb  6 14:10:25 dvr web_php[11483]: ERR [Invalid control parameter: Down]
Feb  6 14:10:25 dvr web_php[9799]: ERR [Invalid control parameter: Down]
Feb  6 14:10:26 dvr web_php[11817]: ERR [Invalid control parameter: Down]
Feb  6 14:10:26 dvr web_php[9800]: ERR [Invalid control parameter: Down]
Feb  6 14:10:26 dvr web_php[9802]: ERR [Invalid control parameter: Down]
Feb  6 14:10:27 dvr web_php[9804]: ERR [Invalid control parameter: Down]
Feb  6 14:10:27 dvr web_php[11697]: ERR [Invalid control parameter: Down]
Feb  6 14:10:32 dvr zmcontrol[11822]: FAT [Can't access zoomRelTele member of object of class ZoneMinder::Control::Amcrest_HTTP]
Feb  6 14:10:33 dvr zmcontrol[11826]: FAT [Can't access zoomRelTele member of object of class ZoneMinder::Control::Amcrest_HTTP]
Feb  6 14:10:35 dvr zmcontrol[11830]: FAT [Can't access zoomRelWide member of object of class ZoneMinder::Control::Amcrest_HTTP]
Feb  6 14:10:36 dvr zmcontrol[11839]: FAT [Can't access zoomRelWide member of object of class ZoneMinder::Control::Amcrest_HTTP]
Feb  6 14:10:43 dvr zmcontrol[11824]: FAT [Can't connect: Connection refused after 11 attempts to /var/run/zm/zmcontrol-1.sock]
Feb  6 14:10:43 dvr web_php[11272]: ERR [/usr/bin/zmcontrol.pl --speed=78 --step=0 --command=zoomRelTele --id=1=>]
Feb  6 14:10:45 dvr zmcontrol[11837]: FAT [Can't connect: Connection refused after 11 attempts to /var/run/zm/zmcontrol-1.sock]
Feb  6 14:10:45 dvr web_php[9804]: ERR [/usr/bin/zmcontrol.pl --speed=54 --step=0 --command=zoomRelWide --id=1=>]
Feb  6 14:11:20 dvr zmcontrol[11844]: FAT [Can't access zoomRelTele member of object of class ZoneMinder::Control::Amcrest_HTTP]
Feb  6 14:11:22 dvr zmcontrol[11848]: FAT [Can't access zoomRelWide member of object of class ZoneMinder::Control::Amcrest_HTTP]

Code: Select all

MariaDB [zm]> SELECT * FROM Controls WHERE id=28\G
*************************** 1. row ***************************
            Id: 28
          Name: Amcrest IP2M-853EW
          Type: Ffmpeg
      Protocol: Amcrest_HTTP
       CanWake: 0
      CanSleep: 0
      CanReset: 1
       CanZoom: 1
   CanAutoZoom: 0
    CanZoomAbs: 1
    CanZoomRel: 0
    CanZoomCon: 0
  MinZoomRange: 0
  MaxZoomRange: 0
   MinZoomStep: 0
   MaxZoomStep: 0
  HasZoomSpeed: 1
  MinZoomSpeed: 1
  MaxZoomSpeed: 100
      CanFocus: 1
  CanAutoFocus: 1
   CanFocusAbs: 1
   CanFocusRel: 1
   CanFocusCon: 0
 MinFocusRange: 1
 MaxFocusRange: 100
  MinFocusStep: 1
  MaxFocusStep: 100
 HasFocusSpeed: 1
 MinFocusSpeed: 1
 MaxFocusSpeed: 8
       CanIris: 1
   CanAutoIris: 1
    CanIrisAbs: 1
    CanIrisRel: 1
    CanIrisCon: 0
  MinIrisRange: 0
  MaxIrisRange: 0
   MinIrisStep: 0
   MaxIrisStep: 0
  HasIrisSpeed: 0
  MinIrisSpeed: 0
  MaxIrisSpeed: 0
       CanGain: 0
   CanAutoGain: 0
    CanGainAbs: 0
    CanGainRel: 0
    CanGainCon: 0
  MinGainRange: 0
  MaxGainRange: 0
   MinGainStep: 0
   MaxGainStep: 0
  HasGainSpeed: 0
  MinGainSpeed: 0
  MaxGainSpeed: 0
      CanWhite: 1
  CanAutoWhite: 1
   CanWhiteAbs: 0
   CanWhiteRel: 0
   CanWhiteCon: 0
 MinWhiteRange: 0
 MaxWhiteRange: 0
  MinWhiteStep: 0
  MaxWhiteStep: 0
 HasWhiteSpeed: 0
 MinWhiteSpeed: 0
 MaxWhiteSpeed: 0
    HasPresets: 1
    NumPresets: 255
 HasHomePreset: 0
 CanSetPresets: 1
       CanMove: 1
   CanMoveDiag: 1
    CanMoveMap: 0
    CanMoveAbs: 0
    CanMoveRel: 0
    CanMoveCon: 0
        CanPan: 1
   MinPanRange: 0
   MaxPanRange: 0
    MinPanStep: 0
    MaxPanStep: 0
   HasPanSpeed: 1
   MinPanSpeed: 1
   MaxPanSpeed: 8
   HasTurboPan: 0
 TurboPanSpeed: 0
       CanTilt: 1
  MinTiltRange: 0
  MaxTiltRange: 0
   MinTiltStep: 0
   MaxTiltStep: 0
  HasTiltSpeed: 1
  MinTiltSpeed: 1
  MaxTiltSpeed: 8
  HasTurboTilt: 0
TurboTiltSpeed: 0
   CanAutoScan: 0
  NumScanPaths: 5

tcg
Posts: 40
Joined: Fri Jan 13, 2012 3:41 pm

Re: New Amcrest firmware breaks PTZ

Post by tcg » Thu Feb 07, 2019 11:56 am

Here's what mine says:

Code: Select all

           Id: 39
          Name: Amcrest841
          Type: Ffmpeg
      Protocol: amcrest841
       CanWake: 0
      CanSleep: 0
      CanReset: 0
       CanZoom: 1
   CanAutoZoom: 0
    CanZoomAbs: 0
    CanZoomRel: 0
    CanZoomCon: 0
  MinZoomRange: NULL
  MaxZoomRange: NULL
   MinZoomStep: NULL
   MaxZoomStep: NULL
  HasZoomSpeed: 0
  MinZoomSpeed: NULL
  MaxZoomSpeed: NULL
      CanFocus: 0
  CanAutoFocus: 0
   CanFocusAbs: 0
   CanFocusRel: 0
   CanFocusCon: 0
 MinFocusRange: NULL
 MaxFocusRange: NULL
  MinFocusStep: NULL
  MaxFocusStep: NULL
 HasFocusSpeed: 0
MinFocusSpeed: NULL
 MaxFocusSpeed: NULL
       CanIris: 0
   CanAutoIris: 0
    CanIrisAbs: 0
    CanIrisRel: 0
    CanIrisCon: 0
  MinIrisRange: NULL
  MaxIrisRange: NULL
   MinIrisStep: NULL
   MaxIrisStep: NULL
  HasIrisSpeed: 0
  MinIrisSpeed: NULL
  MaxIrisSpeed: NULL
       CanGain: 0
   CanAutoGain: 0
    CanGainAbs: 0
    CanGainRel: 0
    CanGainCon: 0
  MinGainRange: NULL
  MaxGainRange: NULL
   MinGainStep: NULL
   MaxGainStep: NULL
  HasGainSpeed: 0
  MinGainSpeed: NULL
  MaxGainSpeed: NULL
      CanWhite: 0
  CanAutoWhite: 0
   CanWhiteAbs: 0
   CanWhiteRel: 0
   CanWhiteCon: 0
 MinWhiteRange: NULL
 MaxWhiteRange: NULL
  MinWhiteStep: NULL
  MaxWhiteStep: NULL
 HasWhiteSpeed: 0
 MinWhiteSpeed: NULL
 MaxWhiteSpeed: NULL
    HasPresets: 1
    NumPresets: 8
 HasHomePreset: 0
 CanSetPresets: 0
       CanMove: 1
   CanMoveDiag: 1
    CanMoveMap: 0
    CanMoveAbs: 0
    CanMoveRel: 0
    CanMoveCon: 0
        CanPan: 1
   MinPanRange: NULL
   MaxPanRange: NULL
    MinPanStep: NULL
    MaxPanStep: NULL
   HasPanSpeed: 0
   MinPanSpeed: NULL
   MaxPanSpeed: NULL
   HasTurboPan: 0
 TurboPanSpeed: NULL
       CanTilt: 1
  MinTiltRange: NULL
  MaxTiltRange: NULL
   MinTiltStep: NULL
   MaxTiltStep: NULL
  HasTiltSpeed: 0
  MinTiltSpeed: NULL
  MaxTiltSpeed: NULL
  HasTurboTilt: 0
TurboTiltSpeed: NULL
   CanAutoScan: 0
  NumScanPaths: 0
Chris

chris_19
Posts: 10
Joined: Mon Feb 04, 2019 1:49 pm

Re: New Amcrest firmware breaks PTZ

Post by chris_19 » Thu Feb 07, 2019 2:34 pm

Thanks Chris!

I was able to get all of the functions supported by your script working with my camera.

The other settings I had in zm.Controls were based on Amcrest's latest HTTP API documentation which is unclear at best. It would seem that the detailed specs for the camera should be listed in a table in the doc rather than having to "reverse engineer" them. But perhaps I've missed something.

I'm hoping to work through the API docs and add the other control options over the next few months. Or at least the options which seem beneficial to nominal use.

What I cannot seem to dig up is good documentation on ZM's Perl control API. I'm sure I'm just not gooogling the right set of terms. Perhaps some kind soul could point me to them? Reading the code of existing camera control modules has helped, but understanding how the web_php foo interacts with the zmcontrol foo would help. For example, I am still in the dark as to what

Code: Select all

web_php[9800]: ERR [Invalid control parameter: DownRight]
means when the DownRight control results in the expected camera response.

TIA for any/all help.

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

Re: New Amcrest firmware breaks PTZ

Post by alabamatoy » Mon Feb 11, 2019 5:37 pm

When working with the PHP controls code I ran into some of these issues, but all of mine were the result of my control script having something like "Downright" when the CSS displayed used "DownRight" as the action.

chris_19
Posts: 10
Joined: Mon Feb 04, 2019 1:49 pm

Re: New Amcrest firmware breaks PTZ

Post by chris_19 » Tue Feb 12, 2019 12:26 am

chris_19 wrote:
Thu Feb 07, 2019 2:34 pm
It would seem that the detailed specs for the camera should be listed in a table in the doc rather than having to "reverse engineer" them. But perhaps I've missed something.
This seems to produce most of the desired specs:

http://<camera_url>/cgi-bin/ptz.cgi?action=getCurrentProtocolCaps&channel=1

chris_19
Posts: 10
Joined: Mon Feb 04, 2019 1:49 pm

Re: New Amcrest firmware breaks PTZ

Post by chris_19 » Thu Feb 14, 2019 1:50 pm

So there are a few issues with the Amcrest control module addressed in this thread. I'll write something up to post here detailing them, but folks may also want to reference this post as well: ZM Perl Control API, etc.

chris_19
Posts: 10
Joined: Mon Feb 04, 2019 1:49 pm

Re: New Amcrest firmware breaks PTZ

Post by chris_19 » Fri Feb 22, 2019 8:58 pm

I cleaned the code up for the Amcrest module provided in this thread and submitted it for inclusion in the code base. It was merged today and should appear in a future release of ZoneMinder.

However, due to the disaster of Amcrest support, the company I work for has returned all of the Amcrest equipment, and we're going back with Dahua which we have verified that we can get good, solid US based support for. In light of that move, I don't plan to develop the Amcrest module further. However, I'll be glad to help with it if someone else picks it up or want to sponsor additional development.

Chris

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

Re: New Amcrest firmware breaks PTZ

Post by alabamatoy » Tue Mar 05, 2019 2:35 pm

chris_19 wrote:
Fri Feb 22, 2019 8:58 pm
However, due to the disaster of Amcrest support, the company I work for has returned all of the Amcrest equipment, and we're going back with Dahua which we have verified that we can get good, solid US based support for.
Chris
Might want to suggest that the company you work for do a bit of research on Dahua before burning any bridges. Here is a good place to start: https://krebsonsecurity.com/2016/10/eur ... -iot-mess/

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests