mihai-dinculescu / tapo

Unofficial Tapo API Client. Works with TP-Link Tapo smart devices. Tested with light bulbs (L510, L520, L530, L610, L630), light strips (L900, L920, L930), plugs (P100, P105, P110, P115, P300), hubs (H100), switches (S200B) and sensors (KE100, T100, T110, T300, T310, T315).
MIT License
318 stars 30 forks source link

H200 support #144

Open cecchisandrone opened 7 months ago

cecchisandrone commented 7 months ago

Is there any plan to support H200 hub?

mihai-dinculescu commented 7 months ago

What functionality are you looking for? I believe that there's a high chance that the one that exists for H100 will work for H200 too. Have you tried it?

cecchisandrone commented 7 months ago

No I didn’t try it, I have to buy it that’s why I am asking. Thanks Il 16 dic 2023, 21:16 +0100, Mihai Dinculescu @.***>, ha scritto:

What functionality are you looking for? I believe that there's a high chance that the one that exists for H100 will work for H200 too. Have you tried it? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

mihai-dinculescu commented 7 months ago

If you end up giving it a try, please let us know how it goes!

JeyC0b commented 6 months ago

Hello, I just testing H200 and looks it not working: cargo run --example tapo_h100 Finished dev [unoptimized + debuginfo] target(s) in 0.13s Runningtarget/debug/examples/tapo_h100 Error: Http(Error { kind: Timeout, context: None, source: Some(Error { description: "Timeout was reached", code: 28, extra: None }), source_type: Some("curl::error::Error"), local_addr: None, remote_addr: None })

When I triedL530 it works.

mihai-dinculescu commented 6 months ago

Hmm, a timeout error is not what I was expecting.

Can I double-check that you've pulled the correct IP address from the Tapo app? Also, can you please post the logs you get from RUST_LOG=debug cargo run --example tapo_h100?

JeyC0b commented 6 months ago

Sure

My IP is right, because I have static IP for HUB

Linux: tapo_hub

Tapo mobile APP: tapo_hub2

Linux ping: tapo_hub3

mihai-dinculescu commented 6 months ago

Interesting.

As a test, could you please replace the contents of the is_passthrough_supported function with Ok(false) and then see what RUST_LOG=debug cargo run --example tapo_h100 outputs?

JeyC0b commented 6 months ago

It looks same:

tapo_res

idk...

JeyC0b commented 6 months ago

I just tried IP in browser. When I try L530 I will get 200 OK but when I try HUB 200 I will get time out...

mihai-dinculescu commented 6 months ago

Hmm, I get timeouts with H100 when I try to access it from a different network adapter (H100 on Wifi and a PC on LAN). Is it the same case for you?

JeyC0b commented 6 months ago

Ok, HUB 200 is probably using port 443 (HTTPS), when I try it in browser I will get: {}

tapo_res2

tapo_res3

JeyC0b commented 6 months ago

Hmm, I get timeouts with H100 when I try to access it from a different network adapter (H100 on Wifi and a PC on LAN). Is it the same case for you?

I dont have H100

On H200 I will get always timeout on port 80

mihai-dinculescu commented 6 months ago

I was wondering if you have the same setup as me, with the hub on wifi and a PC/laptop on LAN (or a different Wifi) trying to call it.

mihai-dinculescu commented 6 months ago

If you want to try it over HTTPS, you can change the URL at https://github.com/mihai-dinculescu/tapo/blob/a87a062e8293f11966dcc78ffbe86bf830eb605c/tapo/src/api/api_client.rs#L632

JeyC0b commented 6 months ago

If you want to try it over HTTPS, you can change the URL at

https://github.com/mihai-dinculescu/tapo/blob/a87a062e8293f11966dcc78ffbe86bf830eb605c/tapo/src/api/api_client.rs#L632

Problem with SSL: Error: Http(Error { kind: BadServerCertificate, context: None, source: Some(Error { description: "SSL peer certificate or SSH remote key was not OK", code: 60, extra: None }), source_type: Some("curl::error::Error"), local_addr: Some(1.1.1.100:41144), remote_addr: Some(1.1.1.111:443) })

JeyC0b commented 6 months ago

I was wondering if you have the same setup as me, with the hub on wifi and a PC/laptop on LAN (or a different Wifi) trying to call it.

I have: router -> switch -> server, hub 200, PC, Access point

I am on PC and try it with PUTTY from server. Hub is connected with LAN

JeyC0b commented 6 months ago

I found this:

petretiandrea/home-assistant-tapo-p100/issues/578

They have same problem


I am going out, will be back later

mihai-dinculescu commented 6 months ago

Argh, I was afraid of this. This library also supports only the legacy protocol and the newer Klap one.

It might be worth doing one last hurrah and disable the SSL verification by replacing https://github.com/mihai-dinculescu/tapo/blob/main/tapo/src/api/api_client.rs#L68 with

        let client = HttpClient::builder()
            .title_case_headers(true)
            .ssl_options(isahc::config::SslOption::DANGER_ACCEPT_INVALID_CERTS)
            .build()?;

But I wouldn't hold my breath.

I'm considering purchasing a camera and/or H200 to look into the third protocol in the following weeks/months.

JeyC0b commented 6 months ago

Ok,

I tested with ssl_option and same problem: tapo_res4

Nereuxofficial commented 6 months ago

Argh, I was afraid of this. This library also supports only the legacy protocol and the newer Klap one.

It might be worth doing one last hurrah and disable the SSL verification by replacing main/tapo/src/api/api_client.rs#L68 with

        let client = HttpClient::builder()
            .title_case_headers(true)
            .ssl_options(isahc::config::SslOption::DANGER_ACCEPT_INVALID_CERTS)
            .build()?;

But I wouldn't hold my breath.

I'm considering purchasing a camera and/or H200 to look into the third protocol in the following weeks/months.

Hey, I am currently having the same issue. Is there any implementation of the Tapo Camera protocol or documentation of it? I'm having a really hard time reversing it.

I have some network logs and it seems to encrypt communication pretty swiftly on the latest version. It seems to use AES-256-CBC-PKCS#7.

mihai-dinculescu commented 6 months ago

Having a look at the decompiled tapo app would be my first port of call.

Also, this library might might be a useful source of inspiration.

petretiandrea commented 5 months ago

It uses a different protocol, like the one used by Tapo Camera

Nereuxofficial commented 5 months ago

It uses a different protocol, like the one used by Tapo Camera

Yes, however it seems to have changed protocols again in a newer firmware version. In this issue someone seems to have gotten it working, however an authentication packet on the latest firmware looks like this:

{
    "method": "login",
    "params": {
        "cnonce": "9AAF7F6F13190C8F",
        "digest_passwd": "5BBC5A0C5B08876DA6F08A0380AC60ECE55EE135FB8610010E580BEF0A2C37FD9AAF7F6F13190C8F080693488D027476",
        "encrypt_type": "3",
        "username": "admin"
    }
}

Whereas authentication previously looked like this:

"method": "login",
            "params": {
                "hashed": True,
                "password": self.hashedPassword,
                "username": self.user,
            },

If anyone knows how to reset it to the previous authentication mechanism please let me know, i tried resetting the hub and using another fresh account already but the encryption persists for all requests.