I'm developing a new NVR system. But it doesn't support motion detection yet, which is a must-have feature. I'd like to support on-camera motion detection because it should be possible without powerful NVR hardware, and it should be relatively easy for me to develop. Well, that's the theory...I'm struggling though.
Does anyone know a reliable way to get a stream of events (such as motion detected) from Dahua cameras?
I've done some research and have found four ways that "should" work:
PullPoint Notifications
The camera supports up to five active subscriptions. You set one up with the CreatePullPointSubscription method, then use it with the PullMessages method (repeatedly), then tear it down with the Unsubscribe method. This does work...sort of.
The problem is that if my software crashes, I basically leak the subscription. If that happens five times, I have to reboot the camera before I can use it again. (Or track the URL to unsubscribe...but that's a whole mess because the URLs reset when the camera reboots, so some other client might be using a subscription with the same URL, etc.)
I want to build something rock-solid. Of course, I prefer my software / the hardware not crash, etc., but if it does, I want it to come back with no fuss, without leaking resources, etc.
ONVIF has a timeout associated with a subscription to address this problem. Once the timeout passes, the subscription goes away. If I could just keep the timeout only a minute or so in the future, there wouldn't be a problem. But...Dahua apparently implemented it wrong. If my PullMessages request is active for 11 seconds, the timeout advances 110 seconds. So before long it's days and days in the future, and there might as well not be a timeout. Grr.
ONVIF Basic Notifications
This approach requires the camera connect to your software. That's dumb, as described here. In my firewall setup, the cameras can't connect to anything, and I'd like to keep it that way.
ONVIF Metadata Streams
This seems to work fine with Hikvision cameras, but not Dahua ones. I can't seem to set up the stream to have anything useful in it. Detailed notes here[edit: fixed link; it went to the wrong thread before].
edit: actually, it does have motion in it! but I'd still like to get the SetMetadataConfig method to work so I can customize things. Grr.
Dahua proprietary HTTP API
I found a doc called DAHUA HTTP API FOR IPC Version 1.67, and I own a Synology NAS that appears to use this API, urls such as /cgi-bin/eventManager.cgi?action=attach&codes=[VideoMotion].
edit:
with firmware 2.622.0000000.18.R, this doesn't work at all. My Synology device doesn't work either, and there are forum posts about this.
with firmware 2.622.0000000.31.R, it sort of works. The big thing I need is a keepalive—making it send something every N seconds even when there's no event, so I can tell if I lost the connection to the camera or not. I see mentions on the Internet of a keepalive URL parameter, but it doesn't seem to do anything for me.
fwiw, Synology's setup has a dropdown for firmware versions:
edit again: hmm, if I request event type All, as in:
curl -v --digest "http://$USER:$PASSWORD@$HOSTNAME/cgi-bin/eventManager.cgi?action=attach&codes=[All]"
it includes updates on time changes. With a 1-minute interval, that might work as a keepalive. My motion detection connection will drop if NTP is misconfigured or the server is down, which is not great, but it's better than nothing...
Does anyone know a reliable way to get a stream of events (such as motion detected) from Dahua cameras?
I've done some research and have found four ways that "should" work:
- ONVIF PullPoint Notifications
- ONVIF Basic Notifications
- ONVIF Metadata Streams
- Dahua proprietary HTTP API
PullPoint Notifications
The camera supports up to five active subscriptions. You set one up with the CreatePullPointSubscription method, then use it with the PullMessages method (repeatedly), then tear it down with the Unsubscribe method. This does work...sort of.
The problem is that if my software crashes, I basically leak the subscription. If that happens five times, I have to reboot the camera before I can use it again. (Or track the URL to unsubscribe...but that's a whole mess because the URLs reset when the camera reboots, so some other client might be using a subscription with the same URL, etc.)
I want to build something rock-solid. Of course, I prefer my software / the hardware not crash, etc., but if it does, I want it to come back with no fuss, without leaking resources, etc.
ONVIF has a timeout associated with a subscription to address this problem. Once the timeout passes, the subscription goes away. If I could just keep the timeout only a minute or so in the future, there wouldn't be a problem. But...Dahua apparently implemented it wrong. If my PullMessages request is active for 11 seconds, the timeout advances 110 seconds. So before long it's days and days in the future, and there might as well not be a timeout. Grr.
ONVIF Basic Notifications
This approach requires the camera connect to your software. That's dumb, as described here. In my firewall setup, the cameras can't connect to anything, and I'd like to keep it that way.
ONVIF Metadata Streams
This seems to work fine with Hikvision cameras, but not Dahua ones. I can't seem to set up the stream to have anything useful in it. Detailed notes here[edit: fixed link; it went to the wrong thread before].
edit: actually, it does have motion in it! but I'd still like to get the SetMetadataConfig method to work so I can customize things. Grr.
Dahua proprietary HTTP API
I found a doc called DAHUA HTTP API FOR IPC Version 1.67, and I own a Synology NAS that appears to use this API, urls such as /cgi-bin/eventManager.cgi?action=attach&codes=[VideoMotion].
edit:
with firmware 2.622.0000000.18.R, this doesn't work at all. My Synology device doesn't work either, and there are forum posts about this.
with firmware 2.622.0000000.31.R, it sort of works. The big thing I need is a keepalive—making it send something every N seconds even when there's no event, so I can tell if I lost the connection to the camera or not. I see mentions on the Internet of a keepalive URL parameter, but it doesn't seem to do anything for me.
fwiw, Synology's setup has a dropdown for firmware versions:
- < FW V2.460.0000.10.R
- >= FW V2.460.0000.10.R
- >= FW V.640.0000002.0.R
edit again: hmm, if I request event type All, as in:
curl -v --digest "http://$USER:$PASSWORD@$HOSTNAME/cgi-bin/eventManager.cgi?action=attach&codes=[All]"
it includes updates on time changes. With a 1-minute interval, that might work as a keepalive. My motion detection connection will drop if NTP is misconfigured or the server is down, which is not great, but it's better than nothing...
Last edited: