Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unkown error 1003 when trying to login to device #112

Closed
ClementNerma opened this issue Sep 7, 2023 · 21 comments
Closed

Unkown error 1003 when trying to login to device #112

ClementNerma opened this issue Sep 7, 2023 · 21 comments

Comments

@ClementNerma
Copy link
Contributor

Hi there!

I'm currently running a little project after a while, and I'm unable to login to a device, I get an unknown error with code 1003.

Do you know what this means?

@mihai-dinculescu
Copy link
Owner

Please expand on what "after a while" means and what device type you interact with so I can try and replicate the issue.
Are you creating a new ApiClient? A new handler? Or are you using login on an existing client?
Is it a recurrent error, or does it happen only once?

@ClementNerma
Copy link
Contributor Author

Sorry I did not express myself correctly (english is not my first language).
I meant that the problem didn't appear when I started using this library, I only saw it appear since yesterday when I tried to run the app after a while to make some modifications.

I'm interacting with L530 bulbs, I'm creating a new ApiClient for it and calling .login() directly. This call returns the mentioned error.

It happens every time, which means I can't ever login into the bulb.

@mihai-dinculescu
Copy link
Owner

After upgrading my L530 device to firmware 1.2.4, I am getting random 1301 errors that I wasn't getting before. The occurrence is relatively low and can happen in almost any operation.
I am not getting any errors on login, however.

There's something fishy going on.

@ClementNerma
Copy link
Contributor Author

That's weird, indeed. I upgraded the L530 just before using the library so this is probably the culprit, but I don't know what the exact problem is.

@mihai-dinculescu
Copy link
Owner

OK, I've solved the mystery.

Firmware 1.2.4 for HW v1 produces the random 1301 errors I'm getting.
Firmware 1.1.0 for HW v2 produces the 1003 login error you raised.

The request protocol for HW v2 has received a significant change.

I'll look into adding compatibility for the new versions on both HW models, but it will probably take me a few days to get there.

@TTSKarlsson
Copy link

TTSKarlsson commented Sep 12, 2023

I'll just add that my P100's and P115's return 1003 too

@mihai-dinculescu
Copy link
Owner

Release v0.7.3 fixes this issue.

I have tested it with L530 (hw ver 1 and 2) and P110 (hw ver 1) devices.
As I do not have a P110 with hw ver 2, I would appreciate it if someone could confirm whether it works.

@TTSKarlsson
Copy link

I can check this tomorrow morning EU time, I think P115 is also hw2?

@mihai-dinculescu
Copy link
Owner

I can check this tomorrow morning EU time, I think P115 is also hw2?

I know that both L530 and P110 come in both hw v1 and hw v2 variants.
I do not know about P115.

However, it's fairly easy to find out the version by looking at the Device Settings in the Tapo app, or by running get_device_info.

@TTSKarlsson
Copy link

The app shows hw 2.0 for my p100s and hw 1.0 for my p115s.

@ClementNerma
Copy link
Contributor Author

I may have missed something but it doesn't compile on my machine:

image

Using WSL 2 (Ubuntu 23.04)

@mihai-dinculescu
Copy link
Owner

That's odd. Can you please check your Cargo.lock file and see what version of chrono gets used, and if it's pre-0.4.25, investigate why?

@ClementNerma
Copy link
Contributor Author

ClementNerma commented Sep 15, 2023

Ok I think I got why this happens.

Here is an extract from my lockfile:

[[package]]
name = "chrono"
version = "0.4.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b"
dependencies = [
 "iana-time-zone",
 "num-integer",
 "num-traits",
 "serde",
 "winapi",
]

It was exactly like this before updating to the 0.7.3 version. Looking at tapo's Cargo.toml, it only specifies chrono="0.4".

Which means that, when I added tapo as a dependency, chrono's latest version was 0.4.24. And given the tapo's requirements haven't changed, it keps this version.

So I think the tapo crate should specify chrono="0.4.25" instead to ensure it will be no less than that version.

Generally you should always specify an exact version in your lockfile, to ensure the resolved dependency's version will be at least the one you provided.

@TTSKarlsson
Copy link

TTSKarlsson commented Sep 15, 2023

I compile on Win11, and when running it for P100 (hw 2.0, target\debug\examples\tapo_p100.exe) I get this:
Error: Other(Local hash does not match server hash)

Edit: No it works, I used the wrong credentials. Both my hw1 and hw2 plugs seem to work, trying to find out how to use this now more generally.

Edit2: P100 hw2 error, missing field:

→ rust/tapo git:(main) ⋗ cargo run --example tapo_p100 -- on
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
     Running `target\debug\examples\tapo_p100.exe on`
 2023-09-15T06:35:15.591Z INFO  tapo_p100 > Turning device on...
 2023-09-15T06:35:15.605Z INFO  tapo_p100 > Waiting 2 seconds...
 2023-09-15T06:35:17.608Z INFO  tapo_p100 > Turning device off...
 2023-09-15T06:35:17.698Z INFO  tapo_p100 > Device info: PlugDeviceInfoResult { device_id: "8022F9A89B15F45DD9B9949B1205BAC920A027ED", type: "SMART.TAPOPLUG", model: "P100", hw_id: "4D44B233807D5BDA45BEC69DC18AAE09", hw_ver: "2.0", fw_id: "00000000000000000000000000000000", fw_ver: "1.2.1 Build 230804 Rel.190922", oem_id: "6A0E161B05B8FB93E53988B66CE51E30", mac: "30-DE-4B-21-D0-8D", ip: "192.168.2.91", ssid: "-----", signal_level: 3, rssi: -47, specs: "", lang: "en_US", device_on: false, on_time: 0, overheated: false, nickname: "Resin", avatar: "juicer", has_set_location_info: true, region: Some("Europe/-----"), latitude: Some(--), longitude: Some(--), time_diff: Some(60), default_states: PlugDefaultState { type: LastStates, state: PlugState { on: None } } }
Error: Serde(Error("missing field `power_usage`", line: 1, column: 66))
error: process didn't exit successfully: `target\debug\examples\tapo_p100.exe on` (exit code: 1)

@mihai-dinculescu
Copy link
Owner

mihai-dinculescu commented Sep 15, 2023

@TTSKarlsson, can you please prepend your command with RUST_LOG=debug and post here the Device inner response decrypted output line that occurs just before the error?

@mihai-dinculescu
Copy link
Owner

So I think the tapo crate should specify chrono="0.4.25" instead to ensure it will be no less than that version.

Yep, I will add it like so. I was not aware previously that tapo is not compatible with any chrono 0.4 version.
Meanwhile, I hope that cargo update solved your problem?

@TTSKarlsson
Copy link

→ rust/tapo git:(main) ⋗ cargo run --example tapo_p100
    Finished dev [unoptimized + debuginfo] target(s) in 0.43s
     Running `target\debug\examples\tapo_p100.exe`
 2023-09-15T08:49:02.807Z DEBUG tapo::api::api_client > Device url: http://192.168.2.91/app
 2023-09-15T08:49:02.807Z DEBUG tapo::api::protocol::discovery_protocol > Testing the Passthrough protocol...
 2023-09-15T08:49:02.808Z DEBUG tapo::api::protocol::discovery_protocol > Component negotiation request: {"method":"component_nego","params":null}
 2023-09-15T08:49:02.858Z DEBUG tapo::api::protocol::discovery_protocol > Device responded with: TapoResponse { error_code: 1003, result: None }
 2023-09-15T08:49:02.858Z DEBUG tapo::api::protocol::discovery_protocol > Not supported. Setting up the Klap protocol... 2023-09-15T08:49:02.860Z DEBUG tapo::api::protocol::klap_protocol      > Performing handshake1...
 2023-09-15T08:49:02.868Z DEBUG tapo::api::protocol::klap_protocol      > Handshake1 OK
 2023-09-15T08:49:02.868Z DEBUG tapo::api::protocol::klap_protocol      > Performing handshake2...
 2023-09-15T08:49:02.876Z DEBUG tapo::api::protocol::klap_protocol      > Handshake2 OK
 2023-09-15T08:49:02.876Z INFO  tapo_p100                               > Turning device on...
 2023-09-15T08:49:02.876Z DEBUG tapo::api::api_client                   > Device info will change to: Object {"device_on": Bool(true)}
 2023-09-15T08:49:02.876Z DEBUG tapo::api::protocol::klap_protocol      > Request to passthrough: {"method":"set_device_info","params":{"device_on":true},"requestTimeMilis":1694767742876,"terminalUUID":"00-00-00-00-00-00"}
 2023-09-15T08:49:02.971Z DEBUG tapo::api::protocol::klap_protocol      > Device responded with: "{\"error_code\":0}"
 2023-09-15T08:49:02.972Z DEBUG tapo::api::protocol::klap_protocol      > Device inner response: TapoResponse { error_code: 0, result: None }
 2023-09-15T08:49:02.972Z INFO  tapo_p100                               > Waiting 2 seconds...
 2023-09-15T08:49:04.981Z INFO  tapo_p100                               > Turning device off...
 2023-09-15T08:49:04.981Z DEBUG tapo::api::api_client                   > Device info will change to: Object {"device_on": Bool(false)}
 2023-09-15T08:49:04.982Z DEBUG tapo::api::protocol::klap_protocol      > Request to passthrough: {"method":"set_device_info","params":{"device_on":false},"requestTimeMilis":1694767744982,"terminalUUID":"00-00-00-00-00-00"}
 2023-09-15T08:49:05.055Z DEBUG tapo::api::protocol::klap_protocol      > Device responded with: "{\"error_code\":0}"
 2023-09-15T08:49:05.055Z DEBUG tapo::api::protocol::klap_protocol      > Device inner response: TapoResponse { error_code: 0, result: None }
 2023-09-15T08:49:05.055Z DEBUG tapo::api::api_client                   > Get Device info...
 2023-09-15T08:49:05.055Z DEBUG tapo::api::protocol::klap_protocol      > Request to passthrough: {"method":"get_device_info","params":null}
 2023-09-15T08:49:05.069Z DEBUG tapo::api::protocol::klap_protocol      > Device responded with: "{\"result\":{\"device_id\":\"8022F9A89B15F45DD9B9949B1205BAC920A027ED\",\"fw_ver\":\"1.2.1 Build 230804 Rel.190922\",\"hw_ver\":\"2.0\",\"type\":\"SMART.TAPOPLUG\",\"model\":\"P100\",\"mac\":\"30-DE-4B-21-D0-8D\",\"hw_id\":\"4D44B233807D5BDA45BEC69DC18AAE09\",\"fw_id\":\"00000000000000000000000000000000\",\"oem_id\":\"6A0E161B05B8FB93E53988B66CE51E30\",\"ip\":\"192.168.2.91\",\"time_diff\":60,\"ssid\":\"RW1zaWU=\",\"rssi\":-46,\"signal_level\":3,\"auto_off_status\":\"off\",\"auto_off_remain_time\":0,\"latitude\":--,\"longitude\":--,\"lang\":\"en_US\",\"avatar\":\"juicer\",\"region\":\"Europe/--\",\"specs\":\"\",\"nickname\":\"UmVzaW4=\",\"has_set_location_info\":true,\"device_on\":false,\"on_time\":0,\"default_states\":{\"type\":\"last_states\",\"state\":{}},\"overheated\":false},\"error_code\":0}"
 2023-09-15T08:49:05.070Z DEBUG tapo::api::protocol::klap_protocol      > Device inner response: TapoResponse { error_code: 0, result: Some(PlugDeviceInfoResult { device_id: "8022F9A89B15F45DD9B9949B1205BAC920A027ED", type: "SMART.TAPOPLUG", model: "P100", hw_id: "4D44B233807D5BDA45BEC69DC18AAE09", hw_ver: "2.0", fw_id: "00000000000000000000000000000000", fw_ver: "1.2.1 Build 230804 Rel.190922", oem_id: "6A0E161B05B8FB93E53988B66CE51E30", mac: "30-DE-4B-21-D0-8D", ip: "192.168.2.91", ssid: "RW1zaWU=", signal_level: 3, rssi: -46, specs: "", lang: "en_US", device_on: false, on_time: 0, overheated: false, nickname: "UmVzaW4=", avatar: "juicer", has_set_location_info: true, region: Some("Europe/--"), latitude: Some(--), longitude: Some(--), time_diff: Some(60), default_states: PlugDefaultState { type: LastStates, state: PlugState { on: None } } }) }
 2023-09-15T08:49:05.071Z INFO  tapo_p100                               > Device info: PlugDeviceInfoResult { device_id: "8022F9A89B15F45DD9B9949B1205BAC920A027ED", type: "SMART.TAPOPLUG", model: "P100", hw_id: "4D44B233807D5BDA45BEC69DC18AAE09", hw_ver: "2.0", fw_id: "00000000000000000000000000000000", fw_ver: "1.2.1 Build 230804 Rel.190922", oem_id: "6A0E161B05B8FB93E53988B66CE51E30", mac: "30-DE-4B-21-D0-8D", ip: "192.168.2.91", ssid: "Emsie", signal_level: 3, rssi: -46, specs: "", lang: "en_US", device_on: false, on_time: 0, overheated: false, nickname: "Resin", avatar: "juicer", has_set_location_info: true, region: Some("Europe/--"), latitude: Some(--), longitude: Some(--), time_diff: Some(60), default_states: PlugDefaultState { type: LastStates, state: PlugState { on: None } } }
 2023-09-15T08:49:05.071Z DEBUG tapo::api::api_client                   > Get Device usage...
 2023-09-15T08:49:05.071Z DEBUG tapo::api::protocol::klap_protocol      > Request to passthrough: {"method":"get_device_usage","params":null}
 2023-09-15T08:49:05.095Z DEBUG tapo::api::protocol::klap_protocol      > Device responded with: "{\"result\":{\"time_usage\":{\"today\":515,\"past7\":5834,\"past30\":11687}},\"error_code\":0}"
Error: Serde(Error("missing field `power_usage`", line: 1, column: 66))
error: process didn't exit successfully: `target\debug\examples\tapo_p100.exe` (exit code: 1)

I removed the detailed location data.

@mihai-dinculescu
Copy link
Owner

Thank you. Were you always experiencing these errors, or did they start occurring after recent firmware upgrades?

Anyway, it appears that P100 currently provides less energy monitoring data than the lightbulbs. Therefore, I will update the object definitions accordingly. I expect to have the fix ready within the next 24 hours.

@TTSKarlsson
Copy link

TTSKarlsson commented Sep 15, 2023

I never used this library before 😉

When I was looking for options as the go library I used broke, I noticed this one had the same response error code, so I connected the dots.

My Rust is very rusty but if I get this to work I'll probably make a few simple terminal apps using this library for my home network automation. It was several years ago since I did anything in rustlang.

@TTSKarlsson
Copy link

TTSKarlsson commented Sep 15, 2023

Anyway, it appears that P100 currently provides less energy monitoring data than the lightbulbs. Therefore, I will update the object definitions accordingly. I expect to have the fix ready within the next 24 hours.

My P100s doesn't have any energy monitoring data, it's all on the P110/115s (Only the shape differs I think)

@mihai-dinculescu
Copy link
Owner

Version v0.7.4 should fix both issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants