dahua icon indicating copy to clipboard operation
dahua copied to clipboard

Support for iMou devices (DAHUA based)

Open marcinbauer85 opened this issue 4 years ago • 128 comments

Is there chance of this working with imou Ranger 2 cameras, which are based on DAHUA IPC-A22EP?

marcinbauer85 avatar Jun 14 '21 13:06 marcinbauer85

My guess is I need to implement this https://github.com/rroller/dahua/issues/4 and it'll work.

I don't have the hardware to test with so it makes implementing it a little difficult. I'll try to buy one of these cameras soon to test with.

rroller avatar Jun 14 '21 14:06 rroller

Greatly appreciate it!

marcinbauer85 avatar Jun 15 '21 06:06 marcinbauer85

Hi,

I have cameras model IPC-A22E (Imou Ranger2) and another IPC-C22EP-IMOU (Imou Cue2). I have tried adding them and neither of the two models works but I want to try to do more tests and activate the debug mode that you mention in the readme.md. If you need me to try something to test the cameras, do not hesitate to let me know.

gelokatil avatar Jun 16 '21 19:06 gelokatil

@gelokatil that would be the same issue as https://github.com/rroller/dahua/issues/4

I'm buying one of those cameras this week so I can build in support for it. Not sure how long shipping will take, but hopefully not to long.

rroller avatar Jun 17 '21 04:06 rroller

I'm buying one of those cameras this week so I can build in support for it. Not sure how long shipping will take, but hopefully not to long.

I also have two iMou Ranger 2 IPC-A22E cameras. With the windows app Smart PSS can be controlled locally, even the PTZ. When configuring, the program uses port 37777.

If you need us to do any testing, here we are.

Thanks for everything!

rogodra avatar Jun 19 '21 13:06 rogodra

I just ordered this. It’ll arrive Monday and I’ll try to get it working ASAP.

https://www.amazon.com/dp/B08RD2C67R

rroller avatar Jun 20 '21 06:06 rroller

I'am not able to connect to a IPC-HFW2100P. Is it the same issue?

br, PJ

paalj69 avatar Jun 20 '21 15:06 paalj69

@paalj69 I'm not sure.

rroller avatar Jun 20 '21 20:06 rroller

The hardware arrived today. I hope to test it out soon. Will report back as soon as I know more.

rroller avatar Jun 22 '21 06:06 rroller

I have an Imou Ranger 2 (IPC-A22E) too! Let me know if there's a fix/hack/trick to let it work, specially if we can use PTZ controls (so we can control the camera from Home Assistant).

Thanks!

mabusdogma avatar Jun 22 '21 08:06 mabusdogma

Just have a imou Ranger Pro which is a new version having 2K, is it similar with the imou ranger 2? Look like it is IPC-A26HP. note: late confirmation is PC-A46L-LC.

inevity avatar Jun 23 '21 23:06 inevity

@inevity probably the same API.

Just a heads up, I finally got this device hooked up so now I can start hacking away :)

I'll continue to keep you posted. Sorry for the delays!

rroller avatar Jun 24 '21 15:06 rroller

OK this is going to take some work. This camera uses the RPC2 API (which is better because it's json based). The other cameras support the same RPC2 API but the way I coded this integration up was with the REST API. I'll have to either build a translation layer or switch to the RPC2 API (it'll just take some time). I'll see what I can do.

rroller avatar Jun 25 '21 03:06 rroller

OK this is going to take some work. This camera uses the RPC2 API (which is better because it's json based). The other cameras support the same RPC2 API but the way I coded this integration up was with the REST API. I'll have to either build a translation layer or switch to the RPC2 API (it'll just take some time). I'll see what I can do.

Ok rroller, thanks in advance for all your work

gelokatil avatar Jun 26 '21 08:06 gelokatil

OK this is going to take some work. This camera uses the RPC2 API (which is better because it's json based). The other cameras support the same RPC2 API but the way I coded this integration up was with the REST API. I'll have to either build a translation layer or switch to the RPC2 API (it'll just take some time). I'll see what I can do.

Thank you for the work you are doing.

I don't think it's very useful, but with the ConfigTool app, which is inside the ToolBox app, you can change the image settings, like switching the compression of the main video to H264, making it compatible with HA, the bitrate, resolution etc ...

https://www.imoulife.com/support/downloadCenter/tools

rogodra avatar Jun 26 '21 20:06 rogodra

Just to keep everyone posted, I've started to write the first bit of code for this. Nowhere near done, but at least it's a start 😆

rroller avatar Jul 03 '21 15:07 rroller

I have the basic commands working with the RPC2 API (login, logout, get device details). This works great for all my Dahua cameras but it still doesn't work for the iMou camera. It will require more digging to understand what's going on.

rroller avatar Jul 03 '21 17:07 rroller

As far as I can tell, these cameras do not have an HTTP API. Unfortunately you have to connect over a socket and send the commands according to their protocol as seen here https://github.com/mcw0/PoC/blob/master/Dahua-3DES-IMOU-PoC.py That's going to be very painful to implement and to get right.

rroller avatar Jul 03 '21 22:07 rroller

I doubt this will help at all... but I just released 0.8.13 which uses the rpc2 API during the config flow. Can some of you try with the latest 0.8.13 release to see if you get further along when trying to add an iMou camera? I really doubt it will help, but I'd like to rule it out.

rroller avatar Jul 04 '21 00:07 rroller

Hi, I've tested with IPC-A22E and IPC-C22EP-IMOU and gives on both this error message.

DEBUG (MainThread) [custom_components.dahua] Attempting login with URL http://192.168.20.34:80/RPC2_Login INFO (MainThread) [custom_components.dahua] Authenticated with the RPC2 API WARNING (MainThread) [custom_components.dahua] Could not connect to Dahua device via the RPC2 API, falling back to cgi WARNING (MainThread) [custom_components.dahua] Could not connect to Dahua device

Traceback (most recent call last): File "/config/custom_components/dahua/config_flow.py", line 194, in _test_credentials data = await client2.get_machine_name() File "/config/custom_components/dahua/client.py", line 93, in get_machine_name return await self.get(url) File "/config/custom_components/dahua/client.py", line 528, in get raise exception File "/config/custom_components/dahua/client.py", line 516, in get response = await auth.request("GET", url) File "/config/custom_components/dahua/digest.py", line 46, in request response = await self.session.request(method, url, headers=headers, **kwargs) File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 544, in _request await resp.start(conn) File "/usr/local/lib/python3.8/site-packages/aiohttp/client_reqrep.py", line 890, in start message, payload = await self._protocol.read() # type: ignore File "/usr/local/lib/python3.8/site-packages/aiohttp/streams.py", line 604, in read await self._waiter aiohttp.client_exceptions.ServerDisconnectedError: Server disconnected

gelokatil avatar Jul 04 '21 07:07 gelokatil

Imou Ranger 2 (IPC-A22E)

Logger: custom_components.dahua Source: custom_components/dahua/client.py:524 Integration: Dahua (documentation, issues) First occurred: 10:46:42 (1 occurrences) Last logged: 10:46:42

TimeoutError fetching information from http://192.168.1.134:80/cgi-bin/magicBox.cgi?action=getMachineName -

:(

I already use this camera in HA with a standard onvif config, but I have a lot of lag and no PTZ (so I can't control the camera), just image. Should I log out from the ONVIF config before I try this Dahua integration? Not sure

mabusdogma avatar Jul 04 '21 08:07 mabusdogma

Nevermind, i've got the same result with or without the ONVIF integration

mabusdogma avatar Jul 04 '21 08:07 mabusdogma

As far as I can tell, these cameras do not have an HTTP API. Unfortunately you have to connect over a socket and send the commands according to their protocol as seen here https://github.com/mcw0/PoC/blob/master/Dahua-3DES-IMOU-PoC.py That's going to be very painful to implement and to get right.

Hello rroller,

Maybe this is wasting time but I have been playing with the code you have named and I have successfully managed to connect to my camera through the IMOU cloud, passing it as the camera serial parameter. I'm not a programmer at all, but maybe the part of the code that authenticates to the cloud could be redirected to the local IP of the camera instead of going through their cloud.

I have achieved it with this command passing the camera serial as a parameter.

python3 dahua_3des.py --dhp2p XXXXXXXXXXXX -dd

gelokatil avatar Jul 04 '21 10:07 gelokatil

@gelokatil thanks. We don't want to use the cloud here and would like to stay completely local. I should have mentioned this before... the local username is admin and the local password is the "safety code" on the bottom on the camera. You'll also need to figure out the local IP address.

With the mcw0 tools I was able to restart the device which means everything we want to do is doable, but it's doing all of this over socket communication. Writing a client for that is very tedious

rroller avatar Jul 04 '21 17:07 rroller

@mabusdogma that's the same that I'm getting. It's because the Dahua integration is trying to speak HTTP to an API that doesn't understand HTTP so the iMou device just hangs waiting for the right header bytes. If I send the right bytes over a socket I can make progress but it's going to take me awhile to really write something that works and to fully understand the protocol based on @mcw0's work (and hope that the API isn't different from Dahua's HTTP api). Right now this is going to be low on my list of things to do as I want to build in more support for native Dahua cams.

rroller avatar Jul 04 '21 18:07 rroller

Guys, thanks for "alerting" in the post, please let me know how I could help you out.

FYI, I mostly use Dahua undocumented API, not the same as their official CGI API.

mcw0 avatar Jul 04 '21 18:07 mcw0

Guys, thanks for "alerting" in the post, please let me know how I could help you out.

FYI, I mostly use Dahua undocumented API, not the same as their official CGI API.

By the way, the undocumented API I am mostly using working 99.9% with both HTTP/HTTPS and DHIP (DHIP, what I guess you refer as socket), and 2nd, I do have few IMOU devices that I testing/playing with )

mcw0 avatar Jul 04 '21 18:07 mcw0

Whoaaa the legend responded :-) amazing work you’ve done with figuring out these APIs.

Can you point me to an example you might have where you use http? I couldn’t get it to work.

rroller avatar Jul 04 '21 18:07 rroller

Whoaaa the legend responded :-) amazing work you’ve done with figuring out these APIs.

Can you point me to an example you might have where you use http? I couldn’t get it to work.

Well, firstly, thanks and I don't think I am legend, just doing research for fun and NO profit.

Basically, the undocumented JSON API I am using with the DHIP protocol do just work fine fine with normal HTTP/HTTPS as well. I have HTTP/HTTPS implemented in my next version of the script.

Although, there is few tricks to get it working with the "Console", and to give some working examples would make to much work, so I would suggest to wait until i release next version of the script.

However, one thing that's very important to get the "Console" and other "events" to work, is the subscribe to "stream" for events and other stuff.

def open_stream(self, session_id):
    """Open stream session for events and other 'client.Notify'"""
    self.stream = self.remote.get(
        '{}/SubscribeNotify.cgi?sessionId={}'.format(self.uri, session_id),
        verify=False, allow_redirects=False, stream=True
    )

def recv_stream(self):
    """Return events and other 'client.Notify'"""
    return fix_json(self.stream.raw.readline().decode('utf-8'))

Wish I could release the script now, but I have still too much work with other parts of script...

mcw0 avatar Jul 04 '21 19:07 mcw0

Sounds great! Now we have two legends! (and a lot of beta testers) working on it :) Let us now if we can help some way, and thanks a lot!

mabusdogma avatar Jul 04 '21 20:07 mabusdogma