Checking in with an update for anyone who's following.
I'm still pursuing a DIY solution using the API and PowerShell. I'm mostly focused on getting basic pieces of the workflow built (e.g., authentication, parsing responses, etc.), but I have a rough idea of where I'm heading with the first version.
Here's an outline of what I'm aiming for:
- For each IVS rule on each camera, enable logging on the camera.
- Retrieve the start/stop times for each IVS event from each camera.
- Select the event(s) I want to view, use the start/stop times from the log to retrieve the video from the NVR.
The
tools I'm building will let me automate as much of this process as I'd like to later on. I think I could go so far as to have the script create the IVS event records on the NVR so I can see them on the timeline in the playback view, but I don't think this is really necessary since I can build that view as a table or whatever in PowerShell. I also think I could analyze the video stream and monitor for events directly in the packet headers, but I can't think of a use case to make this worth the time right now.
Handling authentication took several days for me to figure out. It looks like Dahua dropped basic auth, which left me with digest authentication. I had to write a function to manage digest auth since Powershell's Invoke-WebRequest commandlet doesn't handle it out of the box. There's a response value that has to be calculated client-side that isn't too bad, but I got stuck on a bug with my implementation for a couple of days due to how pwsh outputs MD5 hash values. I'm mentioning this here just in case someone else searches the forums one day for this same problem. Since the final step of the calculation requires you to take an MD5 hash that uses two other MD5 hashed values as input, you have to change the the two input MD5 hashes to all lower case letters first (because the MD5 algorithm is case sensitive). pwsh outputs the MD5 hash values as hexadecimal, and it uses all upper case letters to display the value (which in turn borks the final MD5 value if you don't change the case first).
I'll post the source for my full set of tools once I have this working. They should actually be flexible enough to reuse for any other automation you might want to do with the cameras or the NVR.