mac-zhou / midea-msmart

This is a library to allow communicating to a Midea AC via the Local area network.
MIT License
147 stars 40 forks source link

cant connect to device #43

Closed seppe912 closed 3 years ago

seppe912 commented 3 years ago

Protocol V3 Got Token and Key from LDPlayer adb. example.py

#!/usr/bin/python3
# -*- coding: UTF-8 -*-
from msmart.device import air_conditioning_device as ac
import logging
logging.basicConfig(level=logging.DEBUG)

device_ip = '192.168.178.80'
device_id = '19791209337257'
device_K1 = '51EC9781C90241F982E49B6985D1D63074C54171FD054DFB8D0B7D107B146396'
device_Token = 'AF388C69453EAE05E184399DFB0AC7F174FEE3D31C04C1FA60D1F6557831C5289851BDAE5B99B39737C554AA4A4DEFC2A1E3261E51391148BF6B31E3AFEC0FD0'

# first take device's ip and id, port is generally 6444
# pip3 install msmart; midea-discover
#device = ac(device_ip, device_id, 6444)
device = ac(device_ip, int(device_id), 6444)

# If the device is using protocol 3 (aka 8370)
# you must authenticate with device's k1 and token.
# adb logcat | grep doKeyAgree
# device.authenticate('YOUR_AC_K1', 'YOUR_AC_TOKEN')
device.authenticate(device_K1, device_Token)

# Refresh the object with the actual state by querying it
device.refresh()
print({
        'id': device.id,
        'name': device.ip,
        'power_state': device.power_state,
        'prompt_tone': device.prompt_tone,
        'target_temperature': device.target_temperature,
        'operational_mode': device.operational_mode,
        'fan_speed': device.fan_speed,
        'swing_mode': device.swing_mode,
        'eco_mode': device.eco_mode,
        'turbo_mode': device.turbo_mode,
        'indoor_temperature': device.indoor_temperature,
        'outdoor_temperature': device.outdoor_temperature,
    })

# Set the state of the device and 
device.power_state = True
device.prompt_tone = True
device.target_temperature = 19
device.operational_mode = ac.operational_mode_enum.cool

# commit the changes with apply()
device.apply()

print({
        'id': device.id,
        'name': device.ip,
        'power_state': device.power_state,
        'prompt_tone': device.prompt_tone,
        'target_temperature': device.target_temperature,
        'operational_mode': device.operational_mode,
        'fan_speed': device.fan_speed,
        'swing_mode': device.swing_mode,
        'eco_mode': device.eco_mode,
        'turbo_mode': device.turbo_mode,
        'indoor_temperature': device.indoor_temperature,
        'outdoor_temperature': device.outdoor_temperature
    })

but nothing changed

Debug-log:

11.08 16:20 msmart.lan   DEBUG    Attempting new connection to 192.168.178.80:6444
11.08 16:20 msmart.lan   DEBUG    Sending to 192.168.178.80:6444 8370004020000000af388c69453eae05e184399dfb0ac7f174fee3d31c04c1fa60d1f6557831c5289851bdae5b99b39737c554aa4a4defc2a1e3261e51391148bf6b31e3afec0fd0
11.08 16:20 msmart.lan   DEBUG    Received from 192.168.178.80:6444 83700040200100004134f2ea3c2f3ec0e71f34c3b073a267d103142605e47e12d6cfdf1def4ee7309382c1c3f64eeca1efe844694840da8911ded11758228052874488e280ef0333
11.08 16:20 msmart.lan   DEBUG    Got TCP key for 192.168.178.80:6444 79ac3d2009746e4c746630de87c87f85ed46ebc57ecb664e4348d7a5b8f14923
11.08 16:20 msmart.command DEBUG    Finalize request data: aa20ac00000000000003418100ff03ff000200000000000000000000000035ae89
11.08 16:20 msmart.lan   DEBUG    Sending to 192.168.178.80:6444 8370008e2066a8a3da2370e7a4a0eabd1d45ef9c95de9f1feb49c84fd92ea90d37bfddef49f907cb8ad08a0af867f7742aa2b19e15a40dd4798a79e2afdf8d8ece07b2e3f2c3e1dde8c342eacdeafaa501fe183b3e8d470e7acc66b6784d9c9caf4630199b0c673771df1bb7eab1d5b277db860b3ba1b3a7a47a0d2b31e45bca13607c2a59956deceb06ba38154ae34a3e0dc56342ef
11.08 16:21 msmart.lan   INFO     Couldn't connect with Device 192.168.178.80:6444
11.08 16:21 msmart.command DEBUG    Finalize request data: aa23ac000000000000024043436603ff003000000000000000000000000001000000c907
11.08 16:21 msmart.lan   DEBUG    Attempting new connection to 192.168.178.80:6444
11.08 16:21 msmart.lan   DEBUG    Sending to 192.168.178.80:6444 8370004020000001af388c69453eae05e184399dfb0ac7f174fee3d31c04c1fa60d1f6557831c5289851bdae5b99b39737c554aa4a4defc2a1e3261e51391148bf6b31e3afec0fd0
11.08 16:21 msmart.lan   DEBUG    Received from 192.168.178.80:6444 8370004020010000f03a3ec73d6c1c587074662fd0a978c8d81a960ae800dc052c14ebf8e16ed173b0c7cbcec01af1bf9d5e4e3c65a8e5e2ef8ed7291bf370c4cc3556b4f1ca3e89
11.08 16:21 msmart.lan   DEBUG    Got TCP key for 192.168.178.80:6444 38b7652a835431644523edf55350a1af644cb5eee56f396576e5088e848b9608
11.08 16:21 msmart.lan   DEBUG    Sending to 192.168.178.80:6444 8370008e2066a08f67f96863e9b1ef25045474b7a8dd0c733db06a8f45a576c69a7d3fa722492b2645d9722e58ae6e2c30f5743977a4ca61260120a138fcf8b6282da635f72319e7bcfd5a63d1c79932a7808a38c966ce2b24dde8b65bdfee9ba6c7a1aff0941267665ebedd7a4d2247ea5abed44a170a9f1f5bd3f98a5889bee7f6d028e33619e6c21c8441643c924a800c78876111
11.08 16:21 msmart.lan   INFO     Couldn't connect with Device 192.168.178.80:6444

thanks for support

mac-zhou commented 3 years ago

token and k1 is right but, the device can't accept command. i want the app log and pcap file.

seppe912 commented 3 years ago

I´ve disconnected the V3 stick (Because i´ve got a V2 Stick too, so currently im using V2, V3 just to test) and reconnect the V3 Stick --> Now i got a new Keypair:

    device_K1 = '424CB084C9FF417683372A449FE264A67CEC21F9FBD24ADD9CAAA575443607FF'
    device_Token = '39EA6B26EE73EF42B8BC5B8C5929727E3F6557391DFFD2E786EB4BC3334C1BD93E62D4EEAC89DCE8E3170CA52C5CA32D65369B2B0CE00BE4816604CEF0B50D8A'

But same error.

12.08 09:01 msmart.lan   DEBUG    Attempting new connection to 192.168.178.80:6444
12.08 09:01 msmart.lan   DEBUG    Sending to 192.168.178.80:6444 8370004020000000eb421c6a0d453f06d3d0f00a34b7e167f8afb99872a2530624353d9118becc2a004c631b96c8ab65422f159dc09b8b80a5ebece03315de932c365d849f3a223d
12.08 09:01 msmart.lan   DEBUG    Received from 192.168.178.80:6444 83700005200f00004552524f52
12.08 09:01 msmart.lan   DEBUG    Attempting new connection to 192.168.178.80:6444
12.08 09:01 msmart.lan   DEBUG    Sending to 192.168.178.80:6444 837000402000000039ea6b26ee73ef42b8bc5b8c5929727e3f6557391dffd2e786eb4bc3334c1bd93e62d4eeac89dce8e3170ca52c5ca32d65369b2b0ce00be4816604cef0b50d8a
12.08 09:01 msmart.lan   DEBUG    Received from 192.168.178.80:6444 8370004020010000b93793d3b40ce6691d8482c958602ef8c67e9fe717463c0e04e9a7a41e57b4441a68c7356d0e3c1e30e9c8a368e33bbe5e1442a441ef41a20fcdcd3bb659f5e1
12.08 09:01 msmart.lan   DEBUG    Got TCP key for 192.168.178.80:6444 6d0466edf2c99321c60bf611d0e1baf40ceaf8aa0ecb128df6717e256c225cae
12.08 09:01 msmart.command DEBUG    Finalize request data: aa20ac00000000000003418100ff03ff00020000000000000000000000002152f9
12.08 09:01 msmart.lan   DEBUG    Sending to 192.168.178.80:6444 8370008e20662885f11725fba95bd251904aa022178b16cef8139d772e87db39eaddc12a55c58e5c810d8bbea7c19dbb704e415bfb199cc6176828238e241bac7f345314d65ff96dae670db9946658f9186c3aabe10772890e08895de035bdc8e0f4a68d58d6f0e126788ec7636f0a567194c73b956e9a429b014aeb79f91ca49c465897e0fbd305dec67fa9d57a51219d180f9b3558
12.08 09:01 msmart.lan   INFO     Couldn't connect with Device 192.168.178.80:6444
12.08 09:01 msmart.command DEBUG    Finalize request data: aa23ac000000000000024043436603ff003000000000000000000000000029000000a503
12.08 09:01 msmart.lan   DEBUG    Attempting new connection to 192.168.178.80:6444
12.08 09:01 msmart.lan   DEBUG    Sending to 192.168.178.80:6444 837000402000000139ea6b26ee73ef42b8bc5b8c5929727e3f6557391dffd2e786eb4bc3334c1bd93e62d4eeac89dce8e3170ca52c5ca32d65369b2b0ce00be4816604cef0b50d8a
12.08 09:01 msmart.lan   DEBUG    Received from 192.168.178.80:6444 83700040200100004762e81a641ba9efe102fb9b3964c39a4b4300cdbb25c68a1453232478cd2b96a045dd1f813493d66a49d3dbafea4a2e6bcb57744fbc7075754f35786af6be9d
12.08 09:01 msmart.lan   DEBUG    Got TCP key for 192.168.178.80:6444 d7ee1434ef9769e5ef8601d12a76c9326c948d6e87f8654ab2360ae3dc03a969
12.08 09:01 msmart.lan   DEBUG    Sending to 192.168.178.80:6444 8370008e2066261dbceb160ffea40237c855d3d7103d0b9fb09afcb0767300b8ebc4a4bb24b58f888ddebe27453addda9627b927b213dc94292f39b6dfb88655990b6e3c491aa18362639549c3dc16a0333e9dc421e3fbde877fc01ef93f98d7ca2c87516a459f4b18b415793ef6cc0b7fdf4b1e36de31ea9daa871dbe1ae502d75cc3594f8879bb88934aa126f6be60c753aff193c2
12.08 09:01 msmart.lan   INFO     Couldn't connect with Device 192.168.178.80:6444

here are Files that you want. I´ve startet the App and put the AC on and off over app. Midea traffic.zip

edit: i´ve just noticed, that there is an Firmewareupdate. Maybe i need zu Update the Firmware?? image

Thanks

mac-zhou commented 3 years ago

Have you noticed that the device_id has changed?

seppe912 commented 3 years ago

nope Device id still the same: 19791209337257

INFO:msmart.cli:Midea Local Data 192.168.178.80 837000b8200f04015a5a0111a8007a80                                                                      000000000000000000000000a99100000012000000000000000000000000000003ed0628a5844485                                                                      ef4501f937db456f370e9e5f4f939ce754af13b17d3d951c5bba106fb18ae0300ff40910de510121                                                                      6d2257804fe941f9f3b7bda6c8256507f13e7784445e5328eb483a660cc2da36682b11e235eef961                                                                      e588bd6fd663cf18f31443d17c3aac03a7656614ae1dca445a59c818543f1acf379d2d8ad51fb38f                                                                      21bfb84f560d393142677f8172711b3b
INFO:msmart.cli:Decrypt Reply: 192.168.178.80 50b2a8c02c190000303030303030503030                                                                      30303030305131463043394431433137383033303030300b6e65745f61635f373830330000000001                                                                      000000040000000000ac00000000000000f0c9d1c17803069fcd0300060103000000000000000000                                                                      000000000000000000000000
DEBUG:msmart.command:Finalize request data: aa20ac00000000000003418100ff03ff0002                                                                      0000000000000000000000002152f9
DEBUG:msmart.lan:Attempting new connection to 192.168.178.80:6444
DEBUG:msmart.lan:Sending to 192.168.178.80:6444 5a5a011168002000000000003c213609                                                                      0c081514a9910000001200000000000000000000000000006b000a76e27eed2c3647e57d8602df8b                                                                      c24133a0909225f1481c3b73abacf8ec0bdaf60a4e381fb221a9a82463236a1b7ea6c55348a760f4                                                                      6d00a17847bcb014
INFO:msmart.lan:Couldn't connect with Device 192.168.178.80:6444
DEBUG:msmart.device:Update from 192.168.178.80:192.168.178.80
INFO:msmart.cli:*** Found a unsupported device - type: '0xac' - version: V3 - ip: 192.168.178.80 - port: 6444 - id: 19791209337257 - upid: 21a2c533659e47fb420f2540213fe52e - sn: 000000P0000000Q1F0C9D1C178030000 - ssid: net_ac_7803
INFO:msmart.cli:+++ This device( 192.168.178.80 ) needs more information to support, open https://github.com/mac-zhou/midea-ac-py

edit: Maybe you see my V2 Stick ID ? 17592186057450

mac-zhou commented 3 years ago

please Update the Firmware.

mac-zhou commented 3 years ago

I can see from the pcap file that the device_id is 19791209337257,id is right. Is V2 Stick running normally? ip, id, token and k1 are all right, try to update the firemware.

seppe912 commented 3 years ago

ok with Firmwareupdate it works now. Version is 3.0.8 thanks!

seppe912 commented 3 years ago

sorry mac-zhou i think i´ve been a bit to fast. still can´t connect with Device 192.168.178.80:6444 i´ve tried after Firmware update, works 2 times. then about 20 times device couldn´t connect. Ißve unplug und plugged the USB Device, get K1 and Token (still the same) and try again.. not worked.

I´ve done a while loop with apply() from about 40 times it works 1-2 times. here is log from 2 out auf about 40 tests, most apply() dont work.

1st apply() dont work, second apply() worked:

12.08 13:13 msmart.lan   DEBUG    Attempting new connection to 192.168.178.80:6444
12.08 13:13 msmart.lan   DEBUG    Sending to 192.168.178.80:6444 837000402000000117630cdaf5e5ae279b7c6d3fd99d58ce5ca3592b77aa888f956bb9144415034e149d10a859728d95750ffa319900c15b650ba380b1d29049e490035771342050
12.08 13:13 msmart.lan   DEBUG    Received from 192.168.178.80:6444 8370004020010000e243f8fdec365a1afc70aa104f3f08b1af38de6bf895090ab8f89170dd7b06bcbc988d92d04cbbb6fa0479b9fd519ce1c734f4453a347d5c88819ea76624cde0
12.08 13:13 msmart.lan   DEBUG    Got TCP key for 192.168.178.80:6444 bbbce7ed635b4b9f1efde31166d6e31d189797022e414f7ef057da684968abb0
12.08 13:13 msmart.lan   DEBUG    Sending to 192.168.178.80:6444 8370008e2066b9e90980507e9e2d109723557b67d0014c1826faa5144e396dfefc4b9fe88723ee8b93ea6aa66e179c974d46a5fd49c77e57f47b8eef15c071e6aa684b8ef0fe9720db1849d09cb98411f98b84461364db9c41496b766138b3513d1b6dbaffe9474cc99f6df9763d271babbd628731b7dea589404f9ae270d953fe1ada9891bbeb1755aceba7bee7abe54b7fe6ff9d32
12.08 13:13 msmart.lan   INFO     Couldn't connect with Device 192.168.178.80:6444
12.08 13:13 msmart.command DEBUG    Finalize request data: aa23ac000000000000024042446603ff0030000000000000000000000000220000006d42
12.08 13:13 msmart.lan   DEBUG    Attempting new connection to 192.168.178.80:6444
12.08 13:13 msmart.lan   DEBUG    Sending to 192.168.178.80:6444 837000402000000117630cdaf5e5ae279b7c6d3fd99d58ce5ca3592b77aa888f956bb9144415034e149d10a859728d95750ffa319900c15b650ba380b1d29049e490035771342050
12.08 13:13 msmart.lan   DEBUG    Received from 192.168.178.80:6444 8370004020010000de77b477479a65bc20a5384f747df5cfa5534e69dea1dc9c39748178bd1db75e3b5cb8783f3426db88aece2e4fe6744d5cd5b43e018df0417aa2c620404e8ce2
12.08 13:13 msmart.lan   DEBUG    Got TCP key for 192.168.178.80:6444 346d3fda235c11b7081db638971d373342afc42c07ac9c538c030a450c16fb9c
12.08 13:13 msmart.lan   DEBUG    Sending to 192.168.178.80:6444 8370008e206674145e491906d010e5b5dd4680e16840d9eff2f795950f20b8429c9f6a2c91f6238e10bde225b24ce47511fe997fd102c21acc865bb34db565da335c5b65a1670b26997b3c18bf1f99e4a6e8c303ccae5f30ccc9c0d52f31206fd00786920bc61c6e6f137a6cd601ab387bedb8ae079deb8e6d92db568034e6af7c3735f2b70c0ad1b06b20c8b9a8f176f6ec77bd7362
12.08 13:13 msmart.lan   DEBUG    Received from 192.168.178.80:6444 8370008e20630a8a2208747febe24bb117b279df3d36fef969be65d8a0717a7b1e5bc0c403c16aa097430fb705ab2093a12ec2d6879ce71c1db790785f2aa88a2f073c5f8cc163cbd47d43c34d11aa04e53a92c6ff1e4f70105b5ff9f9048d85b682abe0ef79a00ee9cc6df1f7fc4e14c38a64097eca36bc7dce81e938c7d1894c9853296b98a0e6432519bd6ef055125877f1e64126
12.08 13:13 msmart.device DEBUG    Update from 192.168.178.80:6444 aa22ac00000000000302c00044667f7f00300000005d66000000000000000000003b97
12.08 13:13 msmart.command DEBUG    Appliance response data: c00044667f7f00300000005d66000000000000000000003b97

after that, i try with my V2. V2 is working without any problems.

mac-zhou commented 3 years ago

delete device.refresh() and try

seppe912 commented 3 years ago

not working.. i´ve installed your latest code.

12.08 16:46 msmart.lan   DEBUG    Attempting new connection to 192.168.178.80:6444
12.08 16:46 msmart.lan   DEBUG    Sending to 192.168.178.80:6444 837000402000000017630cdaf5e5ae279b7c6d3fd99d58ce5ca3592b77aa888f956bb9144415034e149d10a859728d95750ffa319900c15b650ba380b1d29049e490035771342050
12.08 16:46 msmart.lan   DEBUG    Received from 192.168.178.80:6444 8370004020010000951c3c37a2af022d36b1edc85aacfb6f40c4702b51d7d20b3a8ccd30faa5474493f0cd0d8866a78f8afde34511a17049b0b29e000294aeea9913481954b287e7
12.08 16:46 msmart.lan   DEBUG    Got TCP key for 192.168.178.80:6444 47c40d741823a92ae5c60da0dead09aa60cd7bb7777ba1c8497d37dfe032c706
12.08 16:46 msmart.command DEBUG    Finalize request data: aa23ac000000000000024043446603ff003000000000000000000000000036000000c9d1
12.08 16:46 msmart.lan   DEBUG    Sending to 192.168.178.80:6444 8370008e206633a95c6a9f6a13fec1da0a1ad70cd2d7cb1b9cf8b5b12ed8cbb4d5d58284d65524ef2509fbcd1153b13c38a0e1cc56853dcf55e14fb9ef370e8f93f3f2b3b27178be470347d408b4c7a152f9c19f6a191592ce1c186ceb22c7a4519f6f79bb2298d26057e846ce49404fc02dc74ace7c3099c1fa680daa0f867111deb8797e34d3d02de8d193728ca0b1e9c2bb8dca08
12.08 16:47 msmart.lan   INFO     Couldn't connect with Device 192.168.178.80:6444
mac-zhou commented 3 years ago

try new code:

pip uninstall msmart
pip install git+https://github.com/mac-zhou/midea-msmart.git

i add some debug log

seppe912 commented 3 years ago

please see log, i´ve seperated the apply() with a return. Last one is ok, rest not midea2lox8370.log

edit: btw i got new token and K1 in above logs

    device_K1 = 'A5B0939405644E3C95CE0779345F15312C2C49C3945B4CC099B11F63FB09AA2B'
    device_Token = '63F4B04047C71FB2361EC10311F6C4B248A1ADFAC304758EF763FC92AA5E07E1231AD4F05886A955D25210FB9775F093E5D636A3353497CCC160C158BD2F9028'
mac-zhou commented 3 years ago

https://github.com/mac-zhou/midea-msmart/blob/1b38d8d19a1d4e615ec58a44935294bfa28feba7/msmart/command.py#L22 change 0x00 to 0x03, then try.

seppe912 commented 3 years ago

not better.. second and last one is ok, rest not midea2lox8370.log

mac-zhou commented 3 years ago

please join telegram group https://t.me/joinchat/UFSSaqBJE5RqvSOq We can communicate more conveniently

mac-zhou commented 3 years ago

fix by https://github.com/mac-zhou/midea-msmart/commit/1c8e2a5c9357082a356c4814f9e93c05ee36d78d