miio icon indicating copy to clipboard operation
miio copied to clipboard

Token can not be discovered or extracted

Open aholstenson opened this issue 6 years ago • 9 comments

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.

aholstenson avatar Jan 23 '18 17:01 aholstenson

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

thunderace avatar Sep 18 '18 15:09 thunderace

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

Hax2kon avatar Sep 22 '18 06:09 Hax2kon

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 avatar Sep 09 '19 19:09 dazhbog

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.

dazhbog avatar Sep 13 '19 11:09 dazhbog

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)

  • Commands would all work etc etc during the unsecured hotspot from my laptop.
  • Recent iOS MiHome app pairs and everything as fine.
  • The old Android app (last version before they stopped storing tokens on device) no longer seems to be supported, I don't get an error message, but login is slow, as are most functions and session and operations seem to be patchy at best or outright timeout. This would seem deliberate as it was obvious it would eventually be deprecated to prevent access

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

mitchins avatar Dec 22 '19 03:12 mitchins

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?

phrogg avatar Jan 05 '20 12:01 phrogg

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".

cisco-devnet avatar Jan 09 '20 11:01 cisco-devnet

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.

mitchins avatar Jan 09 '20 11:01 mitchins

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

ofen avatar Nov 01 '21 14:11 ofen