Open marcinbauer85 opened 3 years ago
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.
Greatly appreciate it!
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 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.
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!
I just ordered this. It’ll arrive Monday and I’ll try to get it working ASAP.
I'am not able to connect to a IPC-HFW2100P. Is it the same issue?
br, PJ
@paalj69 I'm not sure.
The hardware arrived today. I hope to test it out soon. Will report back as soon as I know more.
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!
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 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!
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 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
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 ...
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 😆
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.
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.
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.
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
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
Nevermind, i've got the same result with or without the ONVIF integration
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 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
@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.
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.
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 )
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.
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...
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!
2021-07-06 14:52:36 WARNING (MainThread) [custom_components.dahua] Could not connect to Dahua device via the RPC2 API, falling back to cgi 2021-07-06 14:52:41 ERROR (MainThread) [custom_components.dahua] TimeoutError fetching information from http://192.168.1.229:80/cgi-bin/magicBox.cgi?action=getMachineName So now must dive into @mcw0 's DHIP api or https API.
I have 5 of these and would absolutely buy you guys a lot of beers/coffees if you can make Imou Ranger 2 work with HA.
You have one more beta tester.
P.S: Do you guys have a buymeacoffee.com link or is there a way to contribute finally?
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.
I know it's kinda unfair to ask an ETA for an open source software like this, but could you still give us a ball park estimate? Days, Weeks, Months?
P.S: Do you guys have a buymeacoffee.com link or is there a way to contribute finally?
@sagarspatil personally I'm not in this for money and don't want anything at all. I just want to help others and help the home automation world :D
I think we just need to wait for @mcw0 script to be released and then take it from there.
P.S: Do you guys have a buymeacoffee.com link or is there a way to contribute finally?
@sagarspatil personally I'm not in this for money and don't want anything at all. I just want to help others and help the home automation world :D
I think we just need to wait for @mcw0 script to be released and then take it from there.
You are so kind. Thank you for all your efforts. Please let us know if we can help in anyway.
P.S: Do you guys have a buymeacoffee.com link or is there a way to contribute finally?
@sagarspatil personally I'm not in this for money and don't want anything at all. I just want to help others and help the home automation world :D
I think we just need to wait for @mcw0 script to be released and then take it from there.
Do my script work in any way with your devices? DHIP/JSON for instance? (you should be able to use other port than TCP/5000, normally TCP/80 works too) DVRIP/JSON? (mostly only work on TCP/37777, but few do actually work on TCP/80 && 5000 too)
If JSON works, I could share my HTTP/HTTPS code that do work with JSON with you.
Best, bashis
P.S: Do you guys have a buymeacoffee.com link or is there a way to contribute finally?
@sagarspatil personally I'm not in this for money and don't want anything at all. I just want to help others and help the home automation world :D
I think we just need to wait for @mcw0 script to be released and then take it from there.
Do my script work in any way with your devices? DHIP/JSON for instance? (you should be able to use other port than TCP/5000, normally TCP/80 works too) DVRIP/JSON? (mostly only work on TCP/37777, but few do actually work on TCP/80 && 5000 too)
If JSON works, I could share my HTTP/HTTPS code that do work with JSON with you.
Best, bashis
Btw, do you have any local access to those devices? What ports is open? You have web GUI?
Maybe my IMOU are more flexible in that sense as i have full HTTP access and DHIP/DVRIP to them.
I know some other "Dahua" devices are based on huawei and has not full "set of features".
@mcw0 I do have local access to the device. In Imou life app, there's a tool called Lan Live. It lists all the cameras with local IP, example 10.10.10.85. When i click on a particular camera, it shows the port as 37777 and asks for username and password. Picture http://imgur.com/gallery/5sfNab4 https://imgur.com/gallery/0eVPkLd
@mcw0 I do have local access to the device. In Imou life app, there's a tool called Lan Live. It lists all the cameras with local IP, example 10.10.10.85. When i click on a particular camera, it shows the port as 37777 and asks for username and password. Picture http://imgur.com/gallery/5sfNab4 https://imgur.com/gallery/0eVPkLd
Cool, that's Dahua old protocol DVRIP, may (or should) use some JSON after the legacy DVRIP login. What ports do you have open on the device? (could you make a NMAP scan of 1-65535?) Can you do HTTP/HTTPS Web to the device?
Sure. On it. Give me a couple of minutes.
@mcw0
Scanning 10.10.10.85 [65535 ports]
Discovered open port 80/tcp on 10.10.10.85
Discovered open port 554/tcp on 10.10.10.85
Discovered open port 37777/tcp on 10.10.10.85
Discovered open port 8086/tcp on 10.10.10.85
Completed SYN Stealth Scan at 21:15, 12.06s elapsed (65535 total ports)
Port 80: 404 - Not Found Port 554: ERR_UNSAFE_PORT Port 37777: Keeps loading, no response Port 8086: Keeps loading, no response
Let me know if you need anything else.
@mcw0
Scanning 10.10.10.85 [65535 ports] Discovered open port 80/tcp on 10.10.10.85 Discovered open port 554/tcp on 10.10.10.85 Discovered open port 37777/tcp on 10.10.10.85 Discovered open port 8086/tcp on 10.10.10.85 Completed SYN Stealth Scan at 21:15, 12.06s elapsed (65535 total ports)
Cool, HTTP, RTSP and DVRIP (TCP/8086 is interesting, seen that on mine too, but not figured yet)
Wow, 404 on port 80 :o - That is weird, you should have WEB GUI on that one. Does my script work on port 80 with 'dhip'? (DVRIP TCP/37777 with the script should work, maybe not get the fully Console, but at least login.. etc.)
Does my script work on port 80 with 'dhip'? (DVRIP TCP/37777 with the script should work, maybe not get the fully Console, but at least login.. etc.)
@mcw0 Could you tell me the exact steps I need to take? I tried to run the python script directly without any modification but it gave me this error
Traceback (most recent call last):
File "C:\Users\sagar\Downloads\dahua.py", line 101, in <module>
import resource
ModuleNotFoundError: No module named 'resource'
@sagarspatil
$ pip install resource (do that on all missing modules)
This is strange...
C:\Users\sagar\Downloads>pip install resource
Requirement already satisfied: resource in c:\users\sagar\appdata\local\programs\python\python39\lib\site-packages (0.2.1)
Requirement already satisfied: python-easyconfig>=0.1.0 in c:\users\sagar\appdata\local\programs\python\python39\lib\site-packages (from resource) (0.1.7)
Requirement already satisfied: JsonSir>=0.0.2 in c:\users\sagar\appdata\local\programs\python\python39\lib\site-packages (from resource) (0.0.2)
Requirement already satisfied: JsonForm>=0.0.2 in c:\users\sagar\appdata\local\programs\python\python39\lib\site-packages (from resource) (0.0.2)
Requirement already satisfied: jsonschema in c:\users\sagar\appdata\local\programs\python\python39\lib\site-packages (from JsonForm>=0.0.2->resource) (2.6.0)
Requirement already satisfied: PyYAML in c:\users\sagar\appdata\local\programs\python\python39\lib\site-packages (from python-easyconfig>=0.1.0->resource) (5.4.1)
Requirement already satisfied: six in c:\users\sagar\appdata\local\programs\python\python39\lib\site-packages (from python-easyconfig>=0.1.0->resource) (1.16.0)
C:\Users\sagar\Downloads>python dahua.py
Traceback (most recent call last):
File "C:\Users\sagar\Downloads\dahua.py", line 101, in <module>
import resource
ModuleNotFoundError: No module named 'resource'
ok, comment out: import resource (# import resource) - you will not be able to use "memory" in "Console#"
But that doesn't matter, just debug stuff for me anyhow
https://stackoverflow.com/questions/37710848/importerror-no-module-named-resource I'm trying to run it on Ubuntu. Give me 2 mins.
P.S: Do you guys have a buymeacoffee.com link or is there a way to contribute finally?
@sagarspatil personally I'm not in this for money and don't want anything at all. I just want to help others and help the home automation world :D I think we just need to wait for @mcw0 script to be released and then take it from there.
Do my script work in any way with your devices? DHIP/JSON for instance? (you should be able to use other port than TCP/5000, normally TCP/80 works too) DVRIP/JSON? (mostly only work on TCP/37777, but few do actually work on TCP/80 && 5000 too)
If JSON works, I could share my HTTP/HTTPS code that do work with JSON with you.
Best, bashis
Hi Bashis,
Like @sagarspatil , I have two IPC-C22E model cameras and two more IPC-A22E models. In both, I can successfully connect with your Dahua-JSON-Debug-Console-v2.py script, although some bugs appear when executing some commands, but data is obtained in some of them.
[*] [Dahua JSON Debug Console 2019-2021 bashis <mcw noemail eu>]
[+] Opening connection to 192.168.20.27 on port 37777: Done
[-] Dahua JSON Console: Attach Console failed, using local only
[+] Login: Success
[+] keepAlive thread: Started
[*] Remote Model: IPC-A22E, Class: IPC, Time: 2021-07-08 17:28:20
[Console] # help
[*] Local cmd:
[+] certificate: Dump some information of remote certificate
[+] config: remote config (-h for params)
[+] console: console instance handling (-h for params)
[+] debug: debug instance (-h for params)
[+] device: Dump some information of remote device
[+] dhp2p: Dump some information of dhp2p
[+] diag: Interim Remote Diagnose (-h for params)
[+] door: open door (-h for params)
[+] events: Subscribe on events from eventManager (-h for params)
[+] fuzz: fuzz service methods (-h for params)
[+] ldiscover: Device Discovery from this script (-h for params)
[+] log: Log stuff (-h for params)
[+] network: Network stuff (-h for params)
[+] memory: Used memeory of this script (-h for params)
[+] pcap: pcap in remote device (-h for params)
[+] rdiscover: Device Discovery from remote device (-h for params)
[+] service: List remote services and "methods" (-h for params)
[+] sshd: Start / Stop (-h for params)
[+] setDebug: Should start produce output from Console in VTO / VTH
[+] telnet: Start / Stop (-h for params)
[+] test-config: New config test (-h for params)
[+] uboot: U-Boot Environment Variables (-h for params)
[+] "quit": "quit" active instance "quit all" to quit from all
[+] "reboot": "reboot" active instance "reboot all" to reboot all
[+] REBOOT: Try force reboot of remote
[+] TEST: TEST function (-h for params)
[Console] # device
[+] [System]
Vendor: Lechange, Build: 2020-07-30 19:17:25, Version: 2.680.0000000.9.R
Device: IPC-A22P-S2, Web: 3.2.1.35284, OEM: 0000000
Package: LC_IPC-Consumer-Hai-Edison_Eng_P
Traceback (most recent call last):
File "Dahua-JSON-Debug-Console-v2.py", line 6720, in <module>
status = DebugConsole ()
File "Dahua-JSON-Debug-Console-v2.py", line 740, in __init__
self.MainConsole ()
File "Dahua-JSON-Debug-Console-v2.py", line 1334, in MainConsole
exec (tmp)
File "<string>", line 1, in <module>
File "Dahua-JSON-Debug-Console-v2.py", line 4162, in GetRemoteInfo
self.devStorage ()
File "Dahua-JSON-Debug-Console-v2.py", line 4022, in devStorage
self.InstanceService (methodName, params = {"name": Device}, start = True)
File "Dahua-JSON-Debug-Console-v2.py", line 3110, in InstanceService
if not self.CheckForService (methodName):
File "Dahua-JSON-Debug-Console-v2.py", line 2875, in CheckForService
if not len (self.RemoteServicesCache):
TypeError: object of type 'bool' has no len ()
Regards
@mcw0
[*] [Dahua JSON Debug Console 2019-2021 bashis <mcw noemail eu>]
[+] Opening connection to 10.10.10.85 on port 37777: Done
[+] Login: Success
[BEGIN SEND (10.10.10.85)] <------------------2259------------------>
a0010000|00000000|00000000|00000000|00000000|00000000|05020101|0000a1aa
[ END SEND (10.10.10.85)] <------------------2259------------------>
[BEGIN RECV (10.10.10.85)] <------------------2379------------------>
b0000068|36000000|010e0100|00000000|00000000|01000000|0600f900|00000002
[ END RECV (10.10.10.85)] <------------------2379------------------>
[BEGIN SEND (10.10.10.85)] <------------------2259------------------>
a0050000|47000000|00000000|00000000|00000000|00000000|05020008|0000a1aa
admin&&C59D83158CB3AA27657D19D075A3E9A5BB264C1BAFA037D65AE9D45E3B2A83FE
[ END SEND (10.10.10.85)] <------------------2259------------------>
[BEGIN RECV (10.10.10.85)] <------------------2365------------------>
b0000068|00000000|00080100|33000000|33040000|01000000|0600f900|00000002
[ END RECV (10.10.10.85)] <------------------2365------------------>
[BEGIN SEND (10.10.10.85)] <------------------2259------------------>
f6000000|34010000|05000000|00000000|34010000|00000000|33040000|00000000
{"id": 5, "method": "system.multicall", "params": [{"method": "magicBox.getDeviceType", "params": null, "session": 1075, "id": 2}, {"method": "magicBox.getDeviceClass", "params": null, "session": 1075, "id": 3}, {"method": "global.getCurrentTime", "params": null, "session": 1075, "id": 4}], "session": 1075}
[ END SEND (10.10.10.85)] <------------------2259------------------>
[BEGIN RECV (10.10.10.85)] <------------------2379------------------>
f6000068|d2000000|05000000|00000000|d2000000|00000000|33040000|00000000
{"result":true,"params":[{"result":true,"id":2,"params":{"type":"IPC-A22E"}},{"result":true,"id":3,"params":{"type":"IPC"}},{"result":true,"id":4,"params":{"time":"2021-07-08 22:11:38"}}],"id":5,"session":1075}
[ END RECV (10.10.10.85)] <------------------2379------------------>
[*] Remote Model: IPC-A22E, Class: IPC, Time: 2021-07-08 22:11:38
[BEGIN SEND (10.10.10.85)] <------------------2259------------------>
f6000000|4a000000|06000000|00000000|4a000000|00000000|33040000|00000000
{"method": "system.listService", "session": 1075, "params": null, "id": 6}
[ END SEND (10.10.10.85)] <------------------2259------------------>
[BEGIN RECV (10.10.10.85)] <------------------2379------------------>
f6000068|5f000000|06000000|00000000|5f000000|00000000|33040000|00000000
{"result":false,"error":{"code":268632064,"message":"InterfaceNotFound"},"id":6,"session":1075}
[ END RECV (10.10.10.85)] <------------------2379------------------>
[BEGIN SEND (10.10.10.85)] <------------------2259------------------>
f6000000|45000000|07000000|00000000|45000000|00000000|33040000|00000000
{"method": "global.logout", "params": null, "session": 1075, "id": 7}
[ END SEND (10.10.10.85)] <------------------2259------------------>
[BEGIN RECV (10.10.10.85)] <------------------2379------------------>
f6000068|33000000|07000000|00000000|33000000|00000000|33040000|00000000
{"result":true,"params":null,"id":7,"session":1075}
[ END RECV (10.10.10.85)] <------------------2379------------------>
[+] Logout
[*] Closed connection to 10.10.10.85 port 37777
[*] All done
[+] Successful instance termination of IPC-A22E (10.10.10.85)
Does this help?
Is there chance of this working with imou Ranger 2 cameras, which are based on DAHUA IPC-A22EP?