We have moved at community.getvera.com

Author Topic: Camera requiring digest auth and UI5, solved.  (Read 1133 times)

Offline rlmalisz

  • Sr. Member
  • ****
  • Posts: 400
  • Karma: +1/-0
Camera requiring digest auth and UI5, solved.
« on: December 10, 2018, 08:46:39 pm »
I posted a few days ago asking for help on this topic, specifically for a Dahua PTZ.  I had tried adding it to UI7 V+, but the setup was too clever (or braindead) for me to master.

A lot of searching online finally led me to this:  https://github.com/git-moe/dahua-camera-ptz

The author had implemented a ton of stuff I don't need for Vera, but he did have a framework that understood digest auth for clients that don't (in my case, UI5).  I had already written a UI5 PTZ implementation file for the Dahuas, so it was pretty easy to strip out what I didn't need from his code, and set the PHP script up on one of our internal servers (no outside access).  Had PTZ working within an hour.  But he hadn't implemented a snapshot, so I set to work on that.  Did stop and modify Apache logging so access hits to the PHP script didn't get logged...since they hit about once a second.  Per client.  Can you say, "fill my disk"?

Got a working snapshot to a web browser, and got it working with Vera.  A little sluggish, but seemed okay.  Tried Homewave, and nada.  PTZ worked fine, no image.

It took a lot (days) of debugging with curl and friends, but I finally figured out what was wrong (by invoking the Vera UI5 "get snapshot" API on that and other cameras).  Most cameras don't return chunk-encoded responses for snapshot...there's just not that much data to deal with.  This Dahua wasn't either, BUT the Apache2 server was cheerfully chunk-encoding darned near everything, including the snapshot my script was getting from the Dahua.  Vera3+UI5 had enough rendering capability to display the snapshots a bit clumsily on the desktop, but the internal webserver on Vera3+UI5 obviously had no idea how to repackage and forward chunk-encoded data.  So any client using the HTTP API interface to fetch an image Vera had fetched from my PHP intermediary got a pile'o'poop that was broken.  For me, that was Homewave, but I could replicate (and debug) the problem in browsers, with curl, etc.

Forced Apache2 to drop down to HTTP1.0 (which doesn't support chunk-encoding) just for this one script, and voila!  Workee!

So I have now (finally) mounted the camera out in the garage in a test location.  And now am not afraid to get the second one I had planned.  Being able to visually check the garage doors away from home has been useful too often to express.  Vera makes that pretty easy, Homewave makes it quick.

Hopefully, there are some nuggest of info that I dug out in the last week that might be of use to some of you.