Skip to content

HTTP Request Question for a Dahua Camera

This isn't directly related to SecuritySpy, although if I can get this question figured out I will be upgrading my license yet again as I will be purchasing a half dozen or more cameras. Otherwise I will be transitioning away from this architecture.

I have a Dahua camera, attempt at getting support from the guy who sold me the cameras was unfruitful (he said he would help then ghosted me), and was not helpful from the company forum (resulted in my question being hidden on their forum). Other forum attempts have not provided any info. So this is my last post and I'm hoping somebody here can help me, else I'm going to be ditching these PTZ cameras and just going with lower quality Pi cameras for my application. The camera in question:

I have two questions.

Question One:

Why is that using this API, I am able to successfully send HTTP Requests to make the camera pan up, pan down, and stop but every other command gives me a 501 error?

I can get up and down to work using this format:

http://192.168.132.117/cgi-bin/ptz.cgi?action=start&channel=0&code=Up&arg1=0&arg2=1&arg3=0

which works and returns <Response [200]>

Similarly down works with:

http://192.168.132.117/cgi-bin/ptz.cgi?action=start&channel=0&code=Down&arg1=0&arg2=1&arg3=0

and returns <Response [200]>

But despite using the Armcrest HTTP API document (and this API doc from Empire Tech which has the same commands), I can't get left, right, zoom, goto_preset or any other commands to work:

http://192.168.132.117/cgi-bin/ptz.cgi&action=start&channel=0&code=Left&arg1=0&arg2=0&arg3=0

<Response [501]>

** this doesn't change even if I pass a number 1-8 to arg2

I used AI to come up with hundreds of possible commands for pan left in case code=Left wasn't the correct one, and NONE of them worked.

Question Two:

Is the secret here that these companies don't want average users using HTTP Requests or ONVIF for their cameras despite advertising these capabilities? Are companies like Blue Iris paying Dahua for an accurate API so they can develop?

Many thanks for any generous help with this last ditch effort to use these cameras.

Comments

  • Hi, I'm a big dummy. I have been wrestling with this issue since February on and off and finally figured it out by using Wireshark to sniff Ben's software created by people who are not big dummies, and it was only then that I saw why some of my requests were working and some were not working.

    The reason why some of the commands were not working is because the non-working commands I was feeding it had ".cgi&action=" which have been ".cgi?action=" and now with that changed, my code can pan left and I'm sure all the other API commands will work as well.

    I will not be looking for a programming job offer anytime soon.

  • Great to hear you worked this out! It's a small error that is an easy one to make.

    Dahua is actually one of the better companies in terms of publishing API specs - most other camera companies don't even bother, and it therefore used to be very difficult for us to add camera-specific profiles, before ONVIF came along and (mostly) solved this.

    In case it helps, here are the commands that SecuritySpy uses for Dahua / Amcrest PTZ:

    Left: cgi-bin/ptz.cgi?action=start&channel=0&code=Left&arg1=SPEED&arg2=SPEED&arg3=0&arg4=0
    Right: cgi-bin/ptz.cgi?action=start&channel=0&code=Right&arg1=SPEED&arg2=SPEED&arg3=0&arg4=0
    Up: cgi-bin/ptz.cgi?action=start&channel=0&code=Up&arg1=SPEED&arg2=SPEED&arg3=0&arg4=0
    Down: cgi-bin/ptz.cgi?action=start&channel=0&code=Down&arg1=SPEED&arg2=SPEED&arg3=0&arg4=0
    UpLeft: cgi-bin/ptz.cgi?action=start&channel=0&code=LeftUp&arg1=SPEED&arg2=SPEED&arg3=0&arg4=0
    UpRight: cgi-bin/ptz.cgi?action=start&channel=0&code=RightUp&arg1=SPEED&arg2=SPEED&arg3=0&arg4=0
    DownLeft: cgi-bin/ptz.cgi?action=start&channel=0&code=LeftDown&arg1=SPEED&arg2=SPEED&arg3=0&arg4=0
    DownRight: cgi-bin/ptz.cgi?action=start&channel=0&code=RightDown&arg1=SPEED&arg2=SPEED&arg3=0&arg4=0
    ZoomIn: cgi-bin/ptz.cgi?action=start&channel=0&code=ZoomTele&arg1=0&arg2=SPEED&arg3=0&arg4=0
    ZoomOut: cgi-bin/ptz.cgi?action=start&channel=0&code=ZoomWide&arg1=0&arg2=SPEED&arg3=0&arg4=0
    StopMoving: cgi-bin/ptz.cgi?action=stop&channel=0&code=Left&arg1=0&arg2=0&arg3=0
    StopZooming: cgi-bin/ptz.cgi?action=stop&channel=0&code=ZoomTele&arg1=0&arg2=0&arg3=0
    

    Note that "SPEED" above is a placeholder that should be replaced with an actual number between 1-8.

  • Thank you sir! I really twisted myself into a knot on this one. After feeding my code through a few AI LLMs, I really thought it wasn't formatting on my end since it didn't catch it. Googling found many people complaining about the published API commands not working, but it turns out to be programming error 101 as usual.

    Looking forward to coding and picking up a bunch more of these cameras soon.

  • That code was very helpful, all implemented and working great, thank you again.

  • Great to hear it's all working now! I'm surprised the LLMs didn't pick this up - it's a common error, I'm not immune to it myself :)

Sign In or Register to comment.