aholstenson / miio

Control Mi Home devices, such as Mi Robot Vacuums, Mi Air Purifiers, Mi Smart Home Gateway (Aqara) and more
MIT License
1.87k stars 354 forks source link

Token can not be discovered or extracted #93

Open aholstenson opened 6 years ago

aholstenson commented 6 years ago

This issue is a collection and reminder to look over automatic token extraction and the documentation for how to get a token for things such as the vacuum cleaners and Philips Light Bulbs.

For some great information look into #40 and #80 which both contain information about alternative ways to extract tokens.

thunderace commented 6 years ago

A solution is to install this modified MiHome APP : http://www.kapiba.ru/2017/11/mi-home.html Tokens are displayed in the app

Hax2kon commented 6 years ago

For anyone with android struggling with token, I wrote up this guide. In short, you emulate a rooted android and get the database from it. No need to downgrade phone app.

https://www.reddit.com/r/Xiaomi/comments/9ht0vn/the_easy_workaround_to_get_your_xiaomi_vacuum/?utm_source=reddit-android

dazhbog commented 5 years ago

Newer versions of some peripherals seem to change their token on wifi change. That means that the devices stops responding once the wifi is configured with the {"method":"miIO.config_router","params":{"ssid":"XXX","passwd":"XXX"},"id":X} command.

My guess is that the device gets online once WiFi is set up and it generates/uploads a new token that the app can then access.

It would be interesting to see how the new token exchange occurs and whether the token renewal still takes place if xiaomi's servers are not reachable.

dazhbog commented 5 years ago

For anyone wondering, uninstalling any other Mi Home apps, clearing their data and installing Mi Home 5.4.54 (and restarting the phone) allowed me to get the token from the app's log files.

You will need to click on the smart device in the app for the first time so that Mi Home downloads the token and write it to the log file. The token can then be extracted from the log file that is located in the "Smart home" folder in the sdcard Android directory. After that I was able to control my stuff.

Hope this helps.

mitchins commented 4 years ago

Newer versions of some peripherals seem to change their token on wifi change. That means that the devices stops responding once the wifi is configured with the {"method":"miIO.config_router","params":{"ssid":"XXX","passwd":"XXX"},"id":X} command.

My guess is that the device gets online once WiFi is set up and it generates/uploads a new token that the app can then access.

It would be interesting to see how the new token exchange occurs and whether the token renewal still takes place if xiaomi's servers are not reachable.

I can (and did) verify this!

Prelude: I faced the exact same issue for the first time after buying a Mi Air Purifier Pro (zhimi.airpurifier.v7)

After about two hours of trying to repair with either my laptop or the old Android app I gave up and did the following:

  1. Create a tagged VLAN (pure VLAN only) on my Unifi.
  2. Assign this VLAN to a new wifi network
  3. Have my HassIO instance join with it's integrated intel wifi (Celeron J1900)
  4. Create a DHCP controller and new subnet purely on the VNET. (config below for anyone interested, you could also just create a hotspot too if your network hardware is less sophisticated, or even use a usb network adapter and an old airport or whatever). The important thing to note here is I have not done any IP forwarding or NAT, there's no internet traffic at all from within the VLAN. Thus when the purifier fails to see the Xiaomi servers it doesn't change the token and the original one is valid. Further work on this might be possible to see if certain domains are used for activation, or if the SSL certificates can be forged by MITM proxy or anything similar, I won't do this at this stage as I'm happy not to use the mi app and just use HassIO.
  5. Use miio-cli tool to configure the freshly nuked purifier to join the wifi.
  6. Verify from either another computer on the wifi network or the master host, that the auto-token given initially still works (AND IT DOES! :D )

Test output:

miiocli airpurifier --ip 192.168.100.174 --token <XXXXXXXXXXXXXXXXX> info
Model: zhimi.airpurifier.v7
Hardware version: MW300
Firmware version: 1.4.3_19105
Network: {'localIp': '192.168.100.174', 'mask': '255.255.255.0', 'gw': '192.168.100.1', 'gw_mac': '74:44:01:FC:0F:B0'}
AP: {'rssi': -48, 'ssid': 'LookingGlass', 'bssid': 'FE:EC:DA:2F:89:8E'}

dnsmasq.conf (super slimmed down)

port=0
interface=wlp2s0b1
dhcp-range=192.168.100.3,192.168.100.255,72h
phrogg commented 4 years ago

How do you change the wifi? Via miio or the or pyton-miio (miiocli)? I tried this several times now and I can't get it too work. With this app I was able to extract the tokens from the yeelight app https://github.com/phrogg/GetMiTokens/, however my goal as well as yours is also to get this to work without the app at all. I used my normal network and just dc the router from the internet, was that wrong?

cisco-devnet commented 4 years ago

Hello!

I agree with @mitchins in case of purifier pro and 2s - the behavior is exact as you described in case of stub WiFi network without internet. But I have this issue (changing token) with Purifier 3H "fw_ver":"2.0.5","mcu_fw_ver":"0009","miio_ver":"0.0.5","hw_ver":"esp32".

mitchins commented 4 years ago

Hello!

I agree with @mitchins in case of purifier pro and 2s - the behavior is exact as you described in case of stub WiFi network without internet. But I have this issue (changing token) with Purifier 3H "fw_ver":"2.0.5","mcu_fw_ver":"0009","miio_ver":"0.0.5","hw_ver":"esp32".

I strongly suspect it’s universal to most new xiaomi firmwares across many devices. Why do it for one when you can do it for all.

ofen commented 3 years ago

Managed to get new valid token for mmgg.pet_waterer.s1 from Xiaomi cloud via https://github.com/Squachen/micloud#in-terminal after initial miIO.config_route command