Closed jamesarbrown closed 4 years ago
Hi @tchellomello !
Similar to @jamesarbrown, I have a generic Dahau camera I bought as a Canada Computers branded camera that basically will never get a firmware upgrade. I’m fine with that, as it is a good quality camera at a cheap price, and it’s on a separate VLAN that will never have direct Internet access.
I’m not a python expert, nor am I overly familiar with your python-amcrest library. I was able to fix the HTTP 400 error with the quick and dirty patch shown below, which was referenced by @jamesarbrown in this issue. For simplicity, I truncated the command before the codes array, replaced the array of codes with All, and moved the array to the python requests param field (where it will not be URL encoded). I still have to verify that I’m receiving the VideoMotion events (I made the patch after 23:00 last night). I’ll update this issue when I confirm events are being received and processed by HomeAssistant properly with this patch; without the patch, the Amcrest integration is broken in the current HomeAssistant version if the motion_sensor is configured.
Hope this helps!
--- event.py.orig 2020-04-17 22:16:11.488167900 -0400
+++ event.py 2020-04-17 23:21:46.830314848 -0400
@@ -203,7 +203,8 @@
timeout_cmd = (self._timeout_default, None)
ret = self.command(
- "eventManager.cgi?action=attach&codes=[{0}]".format(eventcodes),
+ 'eventManager.cgi?action=attach&codes=',
+ param='[All]',
retries=retries,
timeout_cmd=timeout_cmd,
stream=True,
@mkbrown
and moved the array to the python requests param field
Ah, that's the part you didn't mention in the HA issue. I was just noticing that you didn't just simply change:
"eventManager.cgi?action=attach&codes=[{0}]".format(eventcodes)
to:
'eventManager.cgi?action=attach&codes=[All]'
But passed '[All]'
as the argument to a command()
parameter named param
. But of course, that method doesn't use that parameter. Now I see you also modified command()
. Could you share how you modified command()
? (Or, actually more likely, _command()
.)
@pnbruckner,
The diff above is exactly how I modified the event.py script. I did say I’m not a python expert ;-p , so I thought command was just using python requests directly, and could leverage the methods like param. Looks like my patch simply stripped out the URL encoded square brackets, avoiding the HTTP 400 error. Kicking up the logging isn’t showing anything, and the logbook is not showing motion events, so it looks like my patch is no better than disabling the motion sensor in the HomeAssistant config. I’ll try your revised test script later today.
Thanks for the assistance!
/Mike
Ok. Yes, that won't work, especially since the requests parameter is params
, not param
. 😃
I did find a way to get that part of the URL not encoded. Basically it would effectively be by using params="codes=[VideoMotion]"
. The params
parameter accepts three different formats -- dictionary, list of tuples, and a string. The first two encode whereas the last does not. But to use this would require changing the API of command()
& _command()
, as well as a change to the event based code.
As I said the in HA issue, I'm not sure it's correct to effectively work around a bug in older Dahua camera firmware that doesn't properly handle correct URLs.
For those coming here with same issue the FW and cameras my model is within
Firmware (last release)
[PAL]DH_IPC-HX5(4)XXX-Adreia_Eng_P_Stream3_V2.420.0009.0.R.20151106
Models
DH-IPC-HFW5502C,DH-IPC-HDBW5502,DH-IPC-HDB5502,DH-IPC-HFW5300E-VF,DH-IPC-HFW5300E-Z,DH-IPC-HFW5300C,DH-IPC-HFW5302C,DH-IPC-HFW5300C-L,DH-IPC-HDBW5300,DH-IPC-HDB5300,DH-IPC-HDBW5302,DH-IPC-HDB5302,DH-IPC-HFW4300E,DH-IPC-HFW4300S,DH-IPC-HDBW4300E,DH-IPC-HDW4300S,DH-IPC-HDW4300C,DH-IPC-HDB4300C,DH-IPC-HDB4300F-PT,DH-IPC-HF5200,DH-IPC-HFW5200E-VF,DH-IPC-HFW5200E-Z,DH-IPC-HFW5200C,DH-IPC-HFW5202C,DH-IPC-HFW5200C-L,DH-IPC-HFW5200-IRA,DH-IPC-HFW5200D,DH-IPC-HDBW5200,DH-IPC-HDB5200,DH-IPC-HDBW5202,DH-IPC-HDB5202,DH-IPC-HFW4200E,DH-IPC-HFW4200S,DH-IPC-HDBW4200E,DH-IPC-HDW4200S,DH-IPC-HDW4200C,DH-IPC-HDB4200C,DH-IPC-HDB4200F-PT,DH-IPC-HF5100,DH-IPC-HFW5100E-VF,DH-IPC-HFW5100E-Z,DH-IPC-HFW5100C,DH-IPC-HFW5102C,DH-IPC-HFW5100C-L,DH-IPC-HFW5100-IRA,DH-IPC-HFW5100D,DH-IPC-HDBW5100,DH-IPC-HDB5100,DH-IPC-HFW4100E,DH-IPC-HFW4100S,DH-IPC-HDBW4100E,DH-IPC-HDW4100S,DH-IPC-HDW4100C,DH-IPC-HDB4100C,DH-IPC-HDB4100F-PT
On a Dahua 2015 firmware, no upgrade possible (last firmware)
This URL gets a bad response (400)
http://192.168.1.41:80/cgi-bin/eventManager.cgi?action=attach&codes=%5BAll%5D
This URL works
http://192.168.1.41:80/cgi-bin/eventManager.cgi?action=attach&codes=[All]
A quick fix was detailed here (with Python Amcrest 1.7.0) in HA Reported bug https://github.com/home-assistant/core/issues/33875#issuecomment-615548520
Which seems to be working for me.