aholstenson / miio

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

Device can not be discovered #92

Open aholstenson opened 6 years ago

aholstenson commented 6 years ago

This issue is here to track issues with device discovery, both via miio.devices() and the miio CLI-tool. The network discovery was rewritten in 0.15.0 making it a bit more resilient.

Feel free to add a comment to this issue if you have a device that does not show up when using miio discover.

This issue covers the following old issues: #31, #40 (partially), #84

jghaanstra commented 6 years ago

I just tested CLI-tool version 0.15.1. It's not discovering my Mi Robot Vacuum Cleaner (first gen) anymore. On 0.14.1 I was having issues with timeouts trying to control the robot through miio but on this latest version the device isnt even discovered (and also times one when trying to control).

I also noticed it's not consistent in discovering my Yeelight. Sometimes it doesnt show up during discovery.

Is there something I can do to help troubleshoot?

joiglifberg commented 6 years ago

My Vacuum V1 is discovered every time I run the discover using the 0.15.1 version of the CLI-tool. I'm not sure how to test the control command since I can't seem to figure out a method that the vacuum has. I thought the available methods would be the class methods in the Vacuum class but it doesn't seem like it. All I get is The method activateSpotClean is not available.

Anyone got a hint to give?

jghaanstra commented 6 years ago

@circuuz Try miio control <<ipHere>> token <<tokenHere>> method clean or

aholstenson commented 6 years ago

@jghaanstra Thanks for testing! Could you run the miio-command with debug, something like this: DEBUG=thing\* miio discover and see if you are receiving any handshake replies?

@circuuz miio control uses the method on the resolved device, so any method listed in the documentation should work. Need to spend some time to list all the vacuum methods, but there a few examples in the docs. For spot cleaning you can do something like miio control ipOrIdHere method spotClean.

joiglifberg commented 6 years ago

Unfortunately neither of your suggestions seems correct :(

@jghaanstra When running miio control 192.168.1.174 token 5968677042446568756863446a373035 method clean, I get the following result:

 INFO  Attempting to invoke token on 192.168.1.174
 ERROR  The method token is not available

@aholstenson When running miio control 192.168.1.174 method spotClean, I get the following result:

 INFO  Attempting to invoke method on 192.168.1.174
 ERROR  The method method is not available

It seems like neither of your suggested commands have the correct format I guess.

aholstenson commented 6 years ago

@circuuz Sorry, got the command a bit wrong there. The syntax is miio control ipOrIdHere method arg1 arg2, so to do spot cleaning it would be miio control ipOrIdHere spotClean. I'm going to add more info to the command line help about this in the next release.

jghaanstra commented 6 years ago

When using the debug command (for reference, on Windows it's set DEBUG=* & miio discover) I'm getting different results but was eventually able to track it down.

I deleted the miio directory under my profile folder which holds the tokens.xml. It was added when manually updating the token on 0.14.1 for a device that is not able to auto-discover the token. After deleting miio discover does find my robot. Not able to control it yet but that's a different issue. Discovery for the vacuum cleaner is working here again.

pkol commented 6 years ago

Hi, I've mi air purifier 2 that is not discovered.

$ DEBUG=\* yarn run miio discover 
yarn run v1.3.2
$ /home/pawel/tmp/mio/node_modules/.bin/miio discover
 INFO  Discovering devices. Press Ctrl+C to stop.

  th:discovery:miio Searching every 100000 ms +0ms
  miio:network Grabbing reference to network +0ms
  miio:network Making network active, creating socket +1ms
  miio:network Network bound to port 53051 +5ms
  th:discovery:miio Searching for services +8ms
  miio:packet -> <Buffer 21 31 00 20 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +0ms
yarn run miio --version
yarn run v1.3.2
$ /home/pawel/tmp/mio/node_modules/.bin/miio --version
0.15.6
Done in 0.39s.

PCAP attached. Any ideas?

discover.zip

thorn0 commented 6 years ago

@pkol How many active network interfaces does your machine have? For me, miio discover works on a pc with only one interface. However, on another laptop, where I have virtual networks for VMs, it doesn't work. Apparently, it sends requests or listens to the wrong interface.

thorn0 commented 6 years ago

Indeed, in lib/network.js, I hardcoded the address of the right interface into the _socket.bind call:

this._socket.bind(43434, '192.168.1.225');

instead of

this._socket.bind();

which led to a successful discovery of my Xiaomi device (Mijia bedside lamp).

I also tried to hardcode 0.0.0.0 there, didn't work. This value is default as per the docs, and apparently it's indeed used, but doesn't work for some reason. I don't know much about UDP, so can't tell what's going on here. As a workaround, we can probably use something like the internal-ip module.

My environment:

pkol commented 6 years ago

@thorn0 I have 10 active interfaces (wifi, ethernet, lot of dockers).

nzhou commented 6 years ago

I have a chuangmi plug v1 that was already configured. It can't be discovered by "miio discover" but if can be discovered normally with python-miio (https://github.com/rytilahti/python-miio) by "mirobo discover".

The versions are

Actually, if I add the "DEBUG=thing*", it seems that the device is found correctly. I don't quite understand why it was not returned normally. Debug output like this: thing:miio:xxxxxx <- Handshake reply: <Buffer f5 e3 7b 3f a5 56 57 fa 5e 0d 9f f0 f4 1d 43 88> +0ms thing:miio:xxxxxx Using automatic token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +8ms thing:miio:xxxxxx -> (5) {"method":"miIO.info","params":[],"id":1} +7ms thing:miio:xxxxxx <- Message: {"result":{"life":14785,"cfg_time":0,"token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","mac":"xxx","fw_ver":"1.2.4_7","hw_ver":"MC200","model":"chuangmi.plug.v1","wifi_fw_ver":"SD878x-14.76.36.p79-702.1.0-WM","ap":{"rssi":-52,"ssid":"NETGEAR","bssid":"xxx"},"netif":{"localIp":"192.168.1.10","mask":"255.255.255.0","gw":"192.168.1.1"},"mmfree":24328,"ot":"ott","otu_stat":[460,453,3,0,3,594],"ott_stat":[1, 0, 408, 278]},"id":1} +217ms thing:miio:xxxxxx <- Handshake reply: <Buffer f5 e3 7b 3f a5 56 57 fa 5e 0d 9f f0 f4 1d 43 88> +567ms

rytilahti commented 6 years ago

If you are using mirobo discover without specifying --handshake, it will use mdns instead of miio protocol for discovery.

lyance commented 6 years ago

Hi there,

I'm unable to get the token with mio 0.15.6 can somebody kindly advise? Thank you.

iMac:miio $ DEBUG=* miio discover INFO Discovering devices. Press Ctrl+C to stop.

th:discovery:miio Searching every 100000 ms +0ms miio:network Grabbing reference to network +0ms miio:network Making network active, creating socket +1ms miio:network Network bound to port 52109 +8ms th:discovery:miio Searching for services +10ms miio:packet -> <Buffer 21 31 00 20 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +0ms miio:packet <- <Buffer 21 31 00 20 00 00 00 00 03 4d 6d a6 5a e3 ea 82 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +6ms miio:packet <- <Buffer 21 31 00 20 00 00 00 00 03 4d 6d a6 5a e3 ea 82 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +1ms thing:miio:554xxxxx <- Handshake reply: +0ms thing:miio:554xxxxx Loading token from storage, device hides token and no token set via options +1ms miio:tokens Loading token storage from /Users/xxx/Library/Application Support/miio/tokens.json +0ms miio:tokens Token storage does not exist +1ms th:discovery:miio Service with id 554xxxxx now available +25ms miio:network Grabbing reference to network +25ms miio:packet -> <Buffer 21 31 00 20 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +18ms miio:packet <- <Buffer 21 31 00 20 00 00 00 00 03 4d 6d a6 5a e3 ea 82 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +2ms miio:packet <- <Buffer 21 31 00 20 00 00 00 00 03 4d 6d a6 5a e3 ea 82 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +1ms thing:miio:554xxxxx <- Handshake reply: +20ms thing:miio:554xxxxx Loading token from storage, device hides token and no token set via options +1ms miio:network Grabbing reference to network +5ms miio:network Releasing reference to network +3ms th:discovery:mapped Service with id 554xxxxx now available via MiioBrowser{} +0ms th:discovery:miio:devices Service with id 554xxxxx now available +0ms Device ID: 554xxxxx Model info: rockrobo.vacuum.v1 Address: 192.168.xx.yy Token: ??? Support: At least generic

miio:packet <- <Buffer 21 31 00 20 00 00 00 00 03 4d 6d a6 5a e3 ea 82 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +484ms miio:packet <- <Buffer 21 31 00 20 00 00 00 00 03 4d 6d a6 5a e3 ea 82 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +0ms thing:miio:554xxxxx <- Handshake reply: +483ms th:discovery:miio Searching for services +2m miio:packet -> <Buffer 21 31 00 20 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +2m miio:packet <- <Buffer 21 31 00 20 00 00 00 00 03 4d 6d a6 5a e3 ea e6 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +4ms miio:packet <- <Buffer 21 31 00 20 00 00 00 00 03 4d 6d a6 5a e3 ea e6 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +0ms thing:miio:554xxxxx <- Handshake reply: +2m miio:packet <- <Buffer 21 31 00 20 00 00 00 00 03 4d 6d a6 5a e3 ea e6 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +504ms miio:packet <- <Buffer 21 31 00 20 00 00 00 00 03 4d 6d a6 5a e3 ea e6 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +0ms thing:miio:554xxxxx <- Handshake reply: +505ms

lyance commented 6 years ago

OK I think I got it figured out. First, the rockrobo F/W I'm using is not giving away the TOKEN to miio AFTER having setup the device. I had RESET the rockrobo (WIFI-reset) and then call miio discover. HOWEVER, despite getting a TOKEN shown after miio discover enumerates the rockrobo -- the TOKEN appears to be not valid when I tried with [nicoh88/homebridge-xiaomi-roborock-vacuum].

So this worked for me - getting the correct TOKEN - using the method for iOS: https://www.home-assistant.io/components/vacuum.xiaomi_miio/

After the very tedious process of extracting the TOKEN and running it through a decryption command -- I finally got the 32 char TOKEN string that works with [nicoh88/homebridge-xiaomi-roborock-vacuum].

WKatGitHub commented 6 years ago

Hi to everyone, my goal is to control mi air purifier 2 (zhimi-airpurifier-m1) in local network while blocking it by firewall for any outbound connections to xiaomi servers. I have issue with that. When in the WiFi network, there is no internet connection (or outbound tcp:80 is blocked), I am loosing the ability to control and read sensors by mi home app or miio cli commands. I suppose that it is intended bug or feature in the mi airpurifier firmware (1.2.4_60), known as ",," in JSON payload.

When comparing JSON payloads: Internet-on: "mmfree":25992,"ot":"ott","otu_stat":[0,0,0,0,0,171] Internet-off: "mmfree":26576,,"otu_stat":[0,0,0,0,0,171] Device-after-reset: "mmfree":24896,,"otu_stat":[0,0,0,0,0,0]

, We can see that, in the last two examples ,"ot":"ott", filed is empty: ",,".

In the python-miio library this issue was solved: https://github.com/rytilahti/python-miio/blob/master/miio/protocol.py#L167

Is there, a chance, that similar solution could be implemented in the miio library?

I use miio v0.15.6 installed on RPi 3B+ with Raspbian Stretch Lite, node v6.14.2, node-red v0.18.6.

Edit: I found that adding this, in file: safeishJSON.js, have fixed all my issues with miio discover / inspect / configure:

// Case 2 Load for devices fail as they return empty JSON payload fields
// e.g. ,"ot":"ott", = ,, when device is not connected with Xiaomi servers
//str = str.replace(',,"otu_stat"', ',"otu_stat"');
str = str.replace(',,', ',');

Internet-on:

user@xxxx:~ $ DEBUG=thing* miio inspect 192.168.0.9 INFO Attempting to inspect 192.168.0.9 thing:miio:pending <- Handshake reply: <Buffer 17 43 dd 09 91 0f 62 a6 28 8d d3 49 8f ae ac 1a> +0ms thing:miio:5xxxxxx4 Identifier of device updated +0ms thing:miio:5xxxxxx4 Using automatic token: 1743dd09910f62a6288dd3498faeac1a +6ms thing:miio:5xxxxxx4 -> (5) {"method":"miIO.info","params":[],"id":1} +7ms thing:miio:5xxxxxx4 <- Message: {"result":{"life":1343,"cfg_time":0,"token":"1743dd09910f62a6288dd3498faeac1a","mac":"xx:xx:xx:xx:xx:xx","fw_ver":"1.2.4_60","hw_ver":"MC200","uid":1xxxxxxxx7,"model":"zhimi.airpurifier.m1","wifi_fw_ver":"SD878x-14.76.36.p79-702.1.0-WM","ap":{"rssi":-71,"ssid":"xxxx","bssid":"xx:xx:xx:xx:xx:xx"},"netif":{"localIp":"192.168.0.9","mask":"255.255.255.0","gw":"192.168.0.1"},"mmfree":27080,"ot":"ott","otu_stat":[0,0,0,0,0,171],"ott_stat":[4, 5, 419, 1883]},"id":1} +78ms thing:miio:5xxxxxx4 -> (5) {"method":"get_prop","params":["power","mode","temp_dec","humidity","aqi","favorite_level","filter1_life","f1_hour_used","use_time","led","led_b","buzzer"],"id":2} +33ms thing:miio:5xxxxxx4 <- Message: {"result":["on","auto",258,51,9,10,84,558,2010792,"on",0,"on"],"id":2} +90ms thing:miio:5xxxxxx4 Property power changed from undefined to true +0ms thing:miio:5xxxxxx4 Property mode changed from undefined to auto +3ms thing:miio:5xxxxxx4 Property temperature changed from undefined to 25.8 +1ms thing:miio:5xxxxxx4 Property humidity changed from undefined to 51 +1ms thing:miio:5xxxxxx4 Property aqi changed from undefined to 9 +1ms thing:miio:5xxxxxx4 Property favoriteLevel changed from undefined to 10 +1ms thing:miio:5xxxxxx4 Property filterLifeRemaining changed from undefined to 84 +1ms thing:miio:5xxxxxx4 Property filterHoursUsed changed from undefined to 558 +0ms thing:miio:5xxxxxx4 Property useTime changed from undefined to 2010792 +1ms thing:miio:5xxxxxx4 Property led changed from undefined to true +0ms thing:miio:5xxxxxx4 Property ledBrightness changed from undefined to bright +0ms thing:miio:5xxxxxx4 Property buzzer changed from undefined to true +0ms thing:miio:5xxxxxx4 -> (5) {"method":"miIO.info","params":[],"id":3} +18ms thing:miio:5xxxxxx4 <- Message: {"result":{"life":1344,"cfg_time":0,"token":"1743dd09910f62a6288dd3498faeac1a","mac":"xx:xx:xx:xx:xx:xx","fw_ver":"1.2.4_60","hw_ver":"MC200","uid":1xxxxxxxx7,"model":"zhimi.airpurifier.m1","wifi_fw_ver":"SD878x-14.76.36.p79-702.1.0-WM","ap":{"rssi":-72,"ssid":"xxxx","bssid":"xx:xx:xx:xx:xx:xx"},"netif":{"localIp":"192.168.0.9","mask":"255.255.255.0","gw":"192.168.0.1"},"mmfree":25992,"ot":"ott","otu_stat":[0,0,0,0,0,171],"ott_stat":[4, 5, 419, 1883]},"id":3} +25ms

Device ID: 5xxxxxx4 Model info: zhimi.airpurifier.m1 Address: 192.168.0.9 Token: 1743dd09910f62a6288dd3498faeac1a via auto-token Support: At least basic

Type info: miio:air-purifier, sensor, miio, air-purifier Capabilities: miio:buzzer, miio:led-brightness, miio:switchable-led, pm2.5, relative-humidity, temperature, switchable-mode, mode, switchable-power, restorable-state, power, state

Firmware version: 1.2.4_60 Hardware version: MC200

WiFi: xxxx (xx:xx:xx:xx:xx:xx) RSSI: -72 WiFi firmware version: SD878x-14.76.36.p79-702.1.0-WM

Remote access (Mi Home App): TCP

Properties:

  • power: true
  • mode: auto
  • temperature: 25.8
  • humidity: 51
  • aqi: 9
  • favoriteLevel: 10
  • filterLifeRemaining: 84
  • filterHoursUsed: 558
  • useTime: 2010792
  • led: true
  • ledBrightness: bright
  • buzzer: true

Internet-off:

user@xxxx:~ $ DEBUG=thing* miio inspect 192.168.0.9 INFO Attempting to inspect 192.168.0.9 thing:miio:pending <- Handshake reply: <Buffer 17 43 dd 09 91 0f 62 a6 28 8d d3 49 8f ae ac 1a> +0ms thing:miio:5xxxxxx4 Identifier of device updated +0ms thing:miio:5xxxxxx4 Using automatic token: 1743dd09910f62a6288dd3498faeac1a +5ms thing:miio:5xxxxxx4 -> (5) {"method":"miIO.info","params":[],"id":1} +7ms thing:miio:5xxxxxx4 <- Message: {"result":{"life":1680,"cfg_time":0,"token":"1743dd09910f62a6288dd3498faeac1a","mac":"xx:xx:xx:xx:xx:xx","fw_ver":"1.2.4_60","hw_ver":"MC200","uid":1xxxxxxxx7,"model":"zhimi.airpurifier.m1","wifi_fw_ver":"SD878x-14.76.36.p79-702.1.0-WM","ap":{"rssi":-72,"ssid":"xxxx","bssid":"xx:xx:xx:xx:xx:xx"},"netif":{"localIp":"192.168.0.9","mask":"255.255.255.0","gw":"192.168.0.1"},"mmfree":27240,,"otu_stat":[0,0,0,0,0,171],"ott_stat":[4, 6, 419, 1883]},"id":1} +71ms thing:miio:5xxxxxx4 <- Invalid JSON SyntaxError: Unexpected token , in JSON at position 389 at Object.parse (native) at module.exports (/usr/lib/node_modules/miio/lib/safeishJSON.js:10:15) at DeviceInfo.onMessage (/usr/lib/node_modules/miio/lib/network.js:367:18) at Socket._socket.on.ex (/usr/lib/node_modules/miio/lib/network.js:160:11) at emitTwo (events.js:106:13) at Socket.emit (events.js:191:7) at UDP.onMessage (dgram.js:561:8) +3ms thing:miio:5xxxxxx4 -> (4) {"method":"miIO.info","params":[],"id":101} +2s thing:miio:5xxxxxx4 <- Message: {"result":{"life":1682,"cfg_time":0,"token":"1743dd09910f62a6288dd3498faeac1a","mac":"xx:xx:xx:xx:xx:xx","fw_ver":"1.2.4_60","hw_ver":"MC200","uid":1xxxxxxxx7,"model":"zhimi.airpurifier.m1","wifi_fw_ver":"SD878x-14.76.36.p79-702.1.0-WM","ap":{"rssi":-71,"ssid":"xxxx","bssid":"xx:xx:xx:xx:xx:xx"},"netif":{"localIp":"192.168.0.9","mask":"255.255.255.0","gw":"192.168.0.1"},"mmfree":27240,,"otu_stat":[0,0,0,0,0,171],"ott_stat":[4, 6, 419, 1883]},"id":101} +550ms thing:miio:5xxxxxx4 <- Invalid JSON SyntaxError: Unexpected token , in JSON at position 389 at Object.parse (native) at module.exports (/usr/lib/node_modules/miio/lib/safeishJSON.js:10:15) at DeviceInfo.onMessage (/usr/lib/node_modules/miio/lib/network.js:367:18) at Socket._socket.on.ex (/usr/lib/node_modules/miio/lib/network.js:160:11) at emitTwo (events.js:106:13) at Socket.emit (events.js:191:7) at UDP.onMessage (dgram.js:561:8) +2ms thing:miio:5xxxxxx4 -> (3) {"method":"miIO.info","params":[],"id":201} +1s thing:miio:5xxxxxx4 <- Message: {"result":{"life":1684,"cfg_time":0,"token":"1743dd09910f62a6288dd3498faeac1a","mac":"xx:xx:xx:xx:xx:xx","fw_ver":"1.2.4_60","hw_ver":"MC200","uid":1xxxxxxxx7,"model":"zhimi.airpurifier.m1","wifi_fw_ver":"SD878x-14.76.36.p79-702.1.0-WM","ap":{"rssi":-73,"ssid":"xxxx","bssid":"xx:xx:xx:xx:xx:xx"},"netif":{"localIp":"192.168.0.9","mask":"255.255.255.0","gw":"192.168.0.1"},"mmfree":26576,,"otu_stat":[0,0,0,0,0,171],"ott_stat":[4, 6, 419, 1883]},"id":201} +384ms thing:miio:5xxxxxx4 <- Invalid JSON SyntaxError: Unexpected token , in JSON at position 389 at Object.parse (native) at module.exports (/usr/lib/node_modules/miio/lib/safeishJSON.js:10:15) at DeviceInfo.onMessage (/usr/lib/node_modules/miio/lib/network.js:367:18) at Socket._socket.on.ex (/usr/lib/node_modules/miio/lib/network.js:160:11) at emitTwo (events.js:106:13) at Socket.emit (events.js:191:7) at UDP.onMessage (dgram.js:561:8) +2ms WARNING Could not find device

Device-after-reset:

user@xxxx:~ $ DEBUG=thing* miio inspect 192.168.13.1 INFO Attempting to inspect 192.168.13.1 thing:miio:pending <- Handshake reply: <Buffer 17 43 dd 09 91 0f 62 a6 28 8d d3 49 8f ae ac 1a> +0ms thing:miio:5xxxxxx4 Identifier of device updated +0ms thing:miio:5xxxxxx4 Using automatic token: 1743dd09910f62a6288dd3498faeac1a +6ms thing:miio:5xxxxxx4 -> (5) {"method":"miIO.info","params":[],"id":1} +6ms thing:miio:5xxxxxx4 <- Message: {"result":{"life":103,"cfg_time":0,"token":"1743dd09910f62a6288dd3498faeac1a","mac":"xx:xx:xx:xx:xx:xx","fw_ver":"1.2.4_60","hw_ver":"MC200","model":"zhimi.airpurifier.m1","wifi_fw_ver":"SD878x-14.76.36.p79-702.1.0-WM","ap":{"rssi":-98,"ssid":"�","bssid":"65:15:00:F9:6C:14"},"netif":{"localIp":"36.102.21.0","mask":"129.74.16.0","gw":"249.108.20.0"},"mmfree":25512,,"otu_stat":[0,0,0,0,0,0],"ott_stat":[0, 0, 0, 0]},"id":1} +20ms thing:miio:5xxxxxx4 <- Invalid JSON SyntaxError: Unexpected token , in JSON at position 366 at Object.parse (native) at module.exports (/usr/lib/node_modules/miio/lib/safeishJSON.js:10:15) at DeviceInfo.onMessage (/usr/lib/node_modules/miio/lib/network.js:367:18) at Socket._socket.on.ex (/usr/lib/node_modules/miio/lib/network.js:160:11) at emitTwo (events.js:106:13) at Socket.emit (events.js:191:7) at UDP.onMessage (dgram.js:561:8) +3ms thing:miio:5xxxxxx4 -> (4) {"method":"miIO.info","params":[],"id":101} +2s thing:miio:5xxxxxx4 <- Message: {"result":{"life":105,"cfg_time":0,"token":"1743dd09910f62a6288dd3498faeac1a","mac":"xx:xx:xx:xx:xx:xx","fw_ver":"1.2.4_60","hw_ver":"MC200","model":"zhimi.airpurifier.m1","wifi_fw_ver":"SD878x-14.76.36.p79-702.1.0-WM","ap":{"rssi":-98,"ssid":"�","bssid":"65:15:00:F9:6C:14"},"netif":{"localIp":"36.102.21.0","mask":"129.74.16.0","gw":"249.108.20.0"},"mmfree":25512,,"otu_stat":[0,0,0,0,0,0],"ott_stat":[0, 0, 0, 0]},"id":101} +30ms thing:miio:5xxxxxx4 <- Invalid JSON SyntaxError: Unexpected token , in JSON at position 366 at Object.parse (native) at module.exports (/usr/lib/node_modules/miio/lib/safeishJSON.js:10:15) at DeviceInfo.onMessage (/usr/lib/node_modules/miio/lib/network.js:367:18) at Socket._socket.on.ex (/usr/lib/node_modules/miio/lib/network.js:160:11) at emitTwo (events.js:106:13) at Socket.emit (events.js:191:7) at UDP.onMessage (dgram.js:561:8) +1ms thing:miio:5xxxxxx4 -> (3) {"method":"miIO.info","params":[],"id":201} +2s thing:miio:5xxxxxx4 <- Message: {"result":{"life":107,"cfg_time":0,"token":"1743dd09910f62a6288dd3498faeac1a","mac":"xx:xx:xx:xx:xx:xx","fw_ver":"1.2.4_60","hw_ver":"MC200","model":"zhimi.airpurifier.m1","wifi_fw_ver":"SD878x-14.76.36.p79-702.1.0-WM","ap":{"rssi":-98,"ssid":"��","bssid":"65:15:00:F9:6C:14"},"netif":{"localIp":"36.102.21.0","mask":"129.74.16.0","gw":"249.108.20.0"},"mmfree":24896,,"otu_stat":[0,0,0,0,0,0],"ott_stat":[0, 0, 0, 0]},"id":201} +12ms thing:miio:5xxxxxx4 <- Invalid JSON SyntaxError: Unexpected token , in JSON at position 367 at Object.parse (native) at module.exports (/usr/lib/node_modules/miio/lib/safeishJSON.js:10:15) at DeviceInfo.onMessage (/usr/lib/node_modules/miio/lib/network.js:367:18) at Socket._socket.on.ex (/usr/lib/node_modules/miio/lib/network.js:160:11) at emitTwo (events.js:106:13) at Socket.emit (events.js:191:7) at UDP.onMessage (dgram.js:561:8) +2ms WARNING Could not find device

Dmurph24 commented 6 years ago

Does anyone have an update on this? I am unable to discover the xiaomi roborock too, even after a wifi reset. It can be discovered after I set it up in the Mi Home app though.

pedrommvv commented 5 years ago

@pkol How many active network interfaces does your machine have? For me, miio discover works on a pc with only one interface. However, on another laptop, where I have virtual networks for VMs, it doesn't work. Apparently, it sends requests or listens to the wrong interface.

That worked for me.

studentIvan commented 5 years ago
  1. check your token and ip from xiaomi mi home app
  2. run miio discover and look at the ID of your gateway
  3. run miio tokens update 87643938 --token xxxxxxxxxxxxxxxxxxxxxxxxxxxx where 87643938 is your id and xxxx... is your token from app
  4. run DEBUG=* miio discover --sync and see all the devices with their data
jezzaaa commented 5 years ago

Hi. I have a light strip and a color globe. The miio discover tool finds them both but only shows the token for one. Enabling debug shows one device (the light strip) has non-zero buffer:

  thing:miio:87425134 <- Handshake reply: <Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00> +526ms
  thing:miio:83894783 <- Handshake reply: <Buffer c5 6a 4c 97 08 e8 cc 86 11 8c 0e 2f 79 7f 69 5a> +516ms

I tried deleting and re-adding in Mi Home app. I tried resetting the light by powering off/on 5 times. I checked that it's in developer mode.

Perhaps this is a new firmware that is not leaking the token? I also tried getting the token from the Mi Home app, by backing up and extracting the miio2 database, and both devices are there but the token field is blank for both. I'm guessing a recent up date to the Mi Home app now hides the token?

studentIvan commented 5 years ago

Hi. I have a light strip and a color globe. The miio discover tool finds them both but only shows the token for one. Enabling debug shows one device (the light strip) has non-zero buffer:

  thing:miio:87425134 <- Handshake reply: <Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00> +526ms
  thing:miio:83894783 <- Handshake reply: <Buffer c5 6a 4c 97 08 e8 cc 86 11 8c 0e 2f 79 7f 69 5a> +516ms

I tried deleting and re-adding in Mi Home app. I tried resetting the light by powering off/on 5 times. I checked that it's in developer mode.

Perhaps this is a new firmware that is not leaking the token? I also tried getting the token from the Mi Home app, by backing up and extracting the miio2 database, and both devices are there but the token field is blank for both. I'm guessing a recent up date to the Mi Home app now hides the token?

you can try to use this app instead http://www.kapiba.ru/2017/11/mi-home.html (is russian, but has all device tokens right in app)

jezzaaa commented 5 years ago

you can try to use this app instead http://www.kapiba.ru/2017/11/mi-home.html (is russian, but has all device tokens right in app)

I tried to install that, but my phone starts to install and then says "App not installed".

Isn't this the standard Mi Home app, but with Russian translation? How would this be any different in terms of storing the tokens in the database?

studentIvan commented 5 years ago

my phone starts to install and then says "App not installed".

Have you tried to delete the original app before?

jezzaaa commented 5 years ago

Thanks, worked!

Have you tried to delete the original app before?

No I hadn't. Logcat confirmed this was the problem:

Restore manifest signatures do not match installed application for com.xiaomi.smarthome

I uninstalled the official app, and then the sideload install worked. The vevs version managed to download my existing light settings, so when I get a minute, I'll see if the database has the tokens. If not, I'll try deleting and re-adding them

jezzaaa commented 5 years ago

Alas, that didn't work. I even deleted the miio2.db* files, and when they were re-created, and the two devices added back (from the cloud) the token field was blank. I even deleted the color bulb and added it back with a different name. The new name showed in the database but the token was blank.

I installed an old version (v5.0.31) of MiHome from apkmirror, but got the same result.

studentIvan commented 5 years ago

@jezzaaa didn't work what exaclty?

jezzaaa commented 5 years ago

Didn't work in that the tokens were still empty.

However, I tried once more, but before uninstalling the latest genuine app, I removed the color bulb. I checked that the /data/data/com.xiaomi.smarthome/ directory was removed. Then I installed the old version of the app from apkmirror, added back the bulb. When I checked the database it now had the tokens.

So now, all good, I manually added the token with CLI tool, and can now correctly access the device. Thankyou!

studentIvan commented 5 years ago

@jezzaaa not sure why you use the database. You had to see the token information on each device like this in the app: image

jezzaaa commented 5 years ago

Wow, that would have been great. However, I don't know where I can see the screen with the tokens that you showed.

The link to Vev's version of MiHome seemed to be just with Russian translation and that's all. I re-installed it now to check, but still can't see anywhere with the tokens. I thought you were just sending me to an old version of the app that still stored the token in the database. I didn't realise Vev's version had more info on the "Network info" screen.

It's also in English. So perhaps your link sent me to a different app? I downloaded the file MiHome_5.4.57_vevs.apk

jezzaaa commented 5 years ago

Sorry, I didn't look hard enough. Now I found the screen. On my phone it was all in English. For anyone else trying to find this, go to the main app screen then:

  1. tap "Mi Home" (bottom left)
  2. tap "All" (top left)
  3. tap on name or icon of light -> light power/color settings page
  4. tap on menu ellipsis (...) at top right -> opens menu
  5. select "General settings" -> General settings page
  6. select "Network info" -> Network info page
  7. read Token value
smotx commented 5 years ago

how to get "ID" of window/door sensor, when i launch sudo miio discover I have :

NFO Discovering devices. Press Ctrl+C to stop.

Device ID: 54739727 Model info: zhimi.airpurifier.m1 Address: 192.168.2.115 Token: 6xxxxxx via auto-token Support: At least basic

Device ID: 55999975 Model info: Unknown Address: 192.168.2.199 Token: ??? Support: Unknown

Device ID: 56787354 Model info: lumi.gateway.v3 Address: 192.168.2.157 Token: ??? Support: At least generic

and... nothing else.

Why i don't see all items ?

studentIvan commented 5 years ago

@smotx have you tried the app I described above?

Roen00 commented 5 years ago

Hello, I have the Xiaomi Gateway eu version. I tried to turn on the dev mode, but I couldn't do It via iOS Mi home app neither via the android app because it can't event find the gateway. I tried to use miio, but I get this stack trace:

miio:packet -> <Buffer 21 31 00 20 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +0ms
  miio:packet <- <Buffer 21 31 00 20 00 00 00 00 05 a8 d7 d7 00 00 00 2b 71 45 72 77 37 69 32 55 5a 59 73 4f 74 49 7a 73> +14ms
  miio:packet <- <Buffer 21 31 00 20 00 00 00 00 05 a8 d7 d7 00 00 00 2b 71 45 72 77 37 69 32 55 5a 59 73 4f 74 49 7a 73> +2ms
  thing:miio:94951383 <- Handshake reply: <Buffer 71 45 72 77 37 69 32 55 5a 59 73 4f 74 49 7a 73> +0ms
  thing:miio:94951383 Using automatic token: 71457277376932555a59734f74497a73 +3ms
  thing:miio:94951383 -> (5) {"method":"miIO.info","params":[],"id":1} +1ms
  miio:packet -> <Buffer 21 31 00 50 00 00 00 00 05 a8 d7 d7 00 00 00 2b ac 97 8b 98 d1 e7 8f 05 a9 3e dd 3a f4 92 32 7f> +7ms
  miio:packet <- <Buffer 21 31 00 30 00 00 00 00 05 a8 d7 d7 00 00 00 2b c6 6d ca 24 24 42 c8 02 c0 c1 6e 5b 9e e5 44 2a> +9ms
  miio:packet <- <Buffer 21 31 00 30 00 00 00 00 05 a8 d7 d7 00 00 00 2b c6 6d ca 24 24 42 c8 02 c0 c1 6e 5b 9e e5 44 2a> +0ms
  thing:miio:94951383 <- Message: `` +13ms
  thing:miio:94951383 <- Invalid JSON SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at module.exports (/Users/user/.nvm/versions/node/v12.2.0/lib/node_modules/miio/lib/safeishJSON.js:10:15)
    at DeviceInfo.onMessage (/Users/user/.nvm/versions/node/v12.2.0/lib/node_modules/miio/lib/network.js:367:18)
    at Socket.<anonymous> (/Users/user/.nvm/versions/node/v12.2.0/lib/node_modules/miio/lib/network.js:160:11)
    at Socket.emit (events.js:196:13)
    at UDP.onMessage [as onmessage] (dgram.js:849:8) +1ms
  miio:packet <- <Buffer 21 31 00 20 00 00 00 00 05 a8 d7 d7 00 00 00 2c 71 45 72 77 37 69 32 55 5a 59 73 4f 74 49 7a 73> +482ms
  miio:packet <- <Buffer 21 31 00 20 00 00 00 00 05 a8 d7 d7 00 00 00 2c 71 45 72 77 37 69 32 55 5a 59 73 4f 74 49 7a 73> +1ms
  thing:miio:94951383 <- Handshake reply: <Buffer 71 45 72 77 37 69 32 55 5a 59 73 4f 74 49 7a 73> +481ms
  thing:miio:94951383 -> (4) {"method":"miIO.info","params":[],"id":101} +2s
  miio:packet -> <Buffer 21 31 00 50 00 00 00 00 05 a8 d7 d7 00 00 00 2d 24 ae 44 60 56 37 dd 6b 6e 88 ea 52 cc bb 34 52> +2s
  miio:packet <- <Buffer 21 31 00 30 00 00 00 00 05 a8 d7 d7 00 00 00 2d 55 da ae de 42 ec bb 49 80 5a 03 8d 61 31 58 cc> +5ms
  miio:packet <- <Buffer 21 31 00 30 00 00 00 00 05 a8 d7 d7 00 00 00 2d 55 da ae de 42 ec bb 49 80 5a 03 8d 61 31 58 cc> +0ms
  thing:miio:94951383 <- Message: `` +5ms
  thing:miio:94951383 <- Invalid JSON SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at module.exports (/Users/user/.nvm/versions/node/v12.2.0/lib/node_modules/miio/lib/safeishJSON.js:10:15)
    at DeviceInfo.onMessage (/Users/user/.nvm/versions/node/v12.2.0/lib/node_modules/miio/lib/network.js:367:18)
    at Socket.<anonymous> (/Users/user/.nvm/versions/node/v12.2.0/lib/node_modules/miio/lib/network.js:160:11)
    at Socket.emit (events.js:196:13)
    at UDP.onMessage [as onmessage] (dgram.js:849:8) +0ms
  thing:miio:94951383 -> (3) {"method":"miIO.info","params":[],"id":201} +2s
  miio:packet -> <Buffer 21 31 00 50 00 00 00 00 05 a8 d7 d7 00 00 00 2f 94 62 da ca 67 31 f0 c8 53 3d ed 20 f3 25 91 59> +2s
  miio:packet <- <Buffer 21 31 00 30 00 00 00 00 05 a8 d7 d7 00 00 00 2f 06 d5 d8 28 f4 1c 83 7d 82 bf c3 bf 68 c2 df b2> +10ms
  miio:packet <- <Buffer 21 31 00 30 00 00 00 00 05 a8 d7 d7 00 00 00 2f 06 d5 d8 28 f4 1c 83 7d 82 bf c3 bf 68 c2 df b2> +0ms
  thing:miio:94951383 <- Message: `` +12ms
  thing:miio:94951383 <- Invalid JSON SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at module.exports (/Users/user/.nvm/versions/node/v12.2.0/lib/node_modules/miio/lib/safeishJSON.js:10:15)
    at DeviceInfo.onMessage (/Users/user/.nvm/versions/node/v12.2.0/lib/node_modules/miio/lib/network.js:367:18)
    at Socket.<anonymous> (/Users/user/.nvm/versions/node/v12.2.0/lib/node_modules/miio/lib/network.js:160:11)
    at Socket.emit (events.js:196:13)
    at UDP.onMessage [as onmessage] (dgram.js:849:8) +0ms

Did anyone have this problem? How to solve that? Is there a way to decode the messages that are sent back to miio?

@edit now it returns different error:

  miio:packet -> <Buffer 21 31 00 20 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +0ms
  miio:packet <- <Buffer 21 31 00 20 00 00 00 00 05 a8 d7 d7 00 00 04 bd 71 45 72 77 37 69 32 55 5a 59 73 4f 74 49 7a 73> +14ms
  miio:packet <- <Buffer 21 31 00 20 00 00 00 00 05 a8 d7 d7 00 00 04 bd 71 45 72 77 37 69 32 55 5a 59 73 4f 74 49 7a 73> +1ms
  thing:miio:94951383 <- Handshake reply: <Buffer 71 45 72 77 37 69 32 55 5a 59 73 4f 74 49 7a 73> +0ms
  thing:miio:94951383 Using automatic token: 71457277376932555a59734f74497a73 +0ms
  thing:miio:94951383 -> (5) {"method":"miIO.info","params":[],"id":1} +1ms
  miio:packet -> <Buffer 21 31 00 50 00 00 00 00 05 a8 d7 d7 00 00 04 bd 12 e5 61 ba ae 99 8a f0 5f c2 8b 46 2c cb 7f 35> +1ms
  miio:packet <- <Buffer 21 31 00 20 00 00 00 00 05 a8 d7 d7 00 00 04 bd 71 45 72 77 37 69 32 55 5a 59 73 4f 74 49 7a 73> +497ms
  miio:packet <- <Buffer 21 31 00 20 00 00 00 00 05 a8 d7 d7 00 00 04 bd 71 45 72 77 37 69 32 55 5a 59 73 4f 74 49 7a 73> +0ms
  thing:miio:94951383 <- Handshake reply: <Buffer 71 45 72 77 37 69 32 55 5a 59 73 4f 74 49 7a 73> +498ms
  thing:miio:94951383 -> (4) {"method":"miIO.info","params":[],"id":101} +2s
  miio:packet -> <Buffer 21 31 00 50 00 00 00 00 05 a8 d7 d7 00 00 04 be a8 25 d7 6d aa 20 77 fb 08 f4 93 65 b0 51 ad 18> +2s
  thing:miio:94951383 -> (3) {"method":"miIO.info","params":[],"id":201} +2s
  miio:packet -> <Buffer 21 31 00 50 00 00 00 00 05 a8 d7 d7 00 00 04 c0 c6 b5 c3 f8 12 49 e1 54 ff 69 99 4a d2 36 ce 2f> +2s
  thing:miio:94951383 -> (2) {"method":"miIO.info","params":[],"id":301} +2s
  miio:packet -> <Buffer 21 31 00 50 00 00 00 00 05 a8 d7 d7 00 00 04 c2 f6 93 3e 21 52 ea dd 47 cb cb 47 f3 1f 2f db dc> +2s
  thing:miio:94951383 -> (1) {"method":"miIO.info","params":[],"id":401} +2s
  miio:packet -> <Buffer 21 31 00 50 00 00 00 00 05 a8 d7 d7 00 00 04 c4 eb 71 85 39 cd 37 61 bc e5 8f 85 a4 8b 4e a6 cf> +2s
  thing:miio:94951383 -> (0) {"method":"miIO.info","params":[],"id":501} +2s
  miio:packet -> <Buffer 21 31 00 50 00 00 00 00 05 a8 d7 d7 00 00 04 c6 b3 7a f3 26 02 b1 59 f1 f5 52 76 1b f7 f8 5c 1f> +2s
  th:discovery:miio Service with id 94951383 now available +12s
  miio:network Grabbing reference to network +12s
  thing:miio:94951383 Using automatic token: 71457277376932555a59734f74497a73 +2s
  thing:miio:94951383 -> (5) {"method":"miIO.info","params":[],"id":502} +0ms
  miio:packet -> <Buffer 21 31 00 50 00 00 00 00 05 a8 d7 d7 00 00 04 c8 7c ba 7b 90 7a 89 f9 e8 b6 8b 74 c3 13 b9 35 f8> +2s
  thing:miio:94951383 -> (4) {"method":"miIO.info","params":[],"id":602} +2s
  miio:packet -> <Buffer 21 31 00 50 00 00 00 00 05 a8 d7 d7 00 00 04 ca 5a 3b f9 f5 0c bd fa 1a ae dd 12 50 13 a9 64 b1> +2s
  thing:miio:94951383 -> (3) {"method":"miIO.info","params":[],"id":702} +2s
  miio:packet -> <Buffer 21 31 00 50 00 00 00 00 05 a8 d7 d7 00 00 04 cc 35 c0 23 9c 3c 8f 06 4d e1 13 24 f5 99 8c bd a1> +2s
  thing:miio:94951383 -> (2) {"method":"miIO.info","params":[],"id":802} +2s
  miio:packet -> <Buffer 21 31 00 50 00 00 00 00 05 a8 d7 d7 00 00 04 ce f4 5d 60 4e 03 60 be d0 4e f5 cd ce be 48 df 2a> +2s
  thing:miio:94951383 -> (1) {"method":"miIO.info","params":[],"id":902} +2s
  miio:packet -> <Buffer 21 31 00 50 00 00 00 00 05 a8 d7 d7 00 00 04 d0 f0 0f 91 8b 82 fc ba ea 8d 32 53 f1 b4 fe 66 8e> +2s
  thing:miio:94951383 -> (0) {"method":"miIO.info","params":[],"id":1002} +2s
  miio:packet -> <Buffer 21 31 00 50 00 00 00 00 05 a8 d7 d7 00 00 04 d2 01 a3 b0 e8 a7 db 35 fa e3 98 37 fc ab 16 20 aa> +2s
  miio:network Releasing reference to network +12s
  th:discovery:mapped Could not map service Error: Could not connect to device, token might be wrong
    at /Users/user/.nvm/versions/node/v12.2.0/lib/node_modules/miio/lib/network.js:324:16 {
  code: 'connection-failure',
  device: null
} +0ms
Coliinnn commented 5 years ago

@studentIvan Does the app you describe work for iPhone as well or is there an alternative? I can't seem to download it and AFAIK iPhones do not support .apk files. I have no Android phone nearby to use. Also the token does not show in the regular Mi Home app, is that correct?

Edit: I have managed to get the tokens of my devices now, but when I try to update them for the devices I get the following error: miio ERROR Could not update token, double-check the given token. Does anyone have suggestions as to how I can progress from here?

Edit 2: After some more looking around, I have found a solution that works for me. Perhaps it'll be useful to anyone who stumbles upon this in the future. The idea is: we need to get the token of the device, but it is hidden in a database file. Once we get this token, we can manually set it using the miio protocol. Hope it helps! In short:

ephestione commented 4 years ago

I just received my second Vacuum Robot V1, first one can be associated with the app no problem but I chose not to, this one being for home, where I would like better control,I wanted to pair it. Well, nothing worked. I tried original Mi Home, set it for Italy, Germany, China, Singapore; reset data of app multiple times, connected directly to the vacuum wifi, reinstalled app. Nothing. I tried miio discover --sync from my laptop while connected to the device's wifi, even after disabling all other network adapters of my laptop (ethernet/virtualbox), I installed the russian modded Mi Home... device cannot be found. I used my main phone, a Xiaomi Mi Mix with cdDroid rom, AND a Samsung Galaxy S4 mini with LineageOS. Nothing. Attached is just a sample screenshot of what happens from the laptop. No device is found. How can I give more useful debugging information? miio

ephestione commented 4 years ago

Update... by checking the italian version of the MIUI forums, I found a testimony where enabling the GPS allowed for device discovery. I disable GPS for every app by default. So now I can connect via the official Mi Home app. I tried the latest version from http://www.kapiba.ru/2017/11/mi-home.html, but it won't show the token in the network info, only up to the MAC address. I also tried finding a past version but those files are nowhere.

ephestione commented 4 years ago

So, last (maybe) update: I did find the older versions... I was using google translator on the whole webpage, and the link the the old versions didn't work, probably because of that. Clicking the link in the original russian page led me to the past versions, where I downloaded 5.4.57, installed it, and surely enough the token was visible. So I can confirm that the latest version available of the modded app, at the time of writing, doesn't show the token.

fubar2 commented 4 years ago

If you are using mirobo discover without specifying --handshake, it will use mdns instead of miio protocol for discovery.

Just in case anyone else needs it, this is (AFAIK) about the easiest way to get your chuangmi plug's token. Worked for me! Was going crazy since no joy using handshake=1

AvailCat commented 4 years ago

I have a very very very old chuangmi.plug.v1, which can not be discovered. Here is a response in debug output:

{
    "result": {
        "life": 864464,
        "cfg_time": 0,
        "token": "*********",
        "mac": "8C:BE:**********",
        "fw_ver": "1.2.4_7",
        "hw_ver": "MC200",
        "model": "chuangmi.plug.v1",
        "wifi_fw_ver": "SD878x-14.76.36.p79-702.1.0-WM",
        "ap": {
            "rssi": -40,
            "ssid": "****",
            "bssid": "F4*****"
        },
        "netif": {
            "localIp": "192.168.3.69",
            "mask": "255.255.255.0",
            "gw": "192.168.3.1"
        },
        "mmfree": 24888,
        "ot": "otu",
        "otu_stat": [
            66,
            56,
            410,
            1,
            409,
            780
        ],
        "ott_stat": [
            14,
            17,
            17,
            1038
        ]
    },
    "id": 1
}

Compare it with another chuangmi.plug.m1 and chuangmi.plug.v3, uid was missing in this device's response. I haven't read codes about discover devices, but maybe this is the reason of device can not be discovered?

By the way, most device in my home ( > 15 devices) except this will hide their token after connected to a WiFI / connected to Mi Home app.

alexmuntean commented 4 years ago

@studentIvan Does the app you describe work for iPhone as well or is there an alternative? I can't seem to download it and AFAIK iPhones do not support .apk files. I have no Android phone nearby to use. Also the token does not show in the regular Mi Home app, is that correct?

Edit: I have managed to get the tokens of my devices now, but when I try to update them for the devices I get the following error: miio ERROR Could not update token, double-check the given token. Does anyone have suggestions as to how I can progress from here?

Edit 2: After some more looking around, I have found a solution that works for me. Perhaps it'll be useful to anyone who stumbles upon this in the future. The idea is: we need to get the token of the device, but it is hidden in a database file. Once we get this token, we can manually set it using the miio protocol. Hope it helps! In short:

  • (using iPhone) make backup using iTunes, unencrypted. (AFAIK Android devices can see the token in the Mi Home app)
  • Read backup using the program iBackupViewer, navigate to AppDomain > com.xiaomi.mihome > search for _mihome. Select the 1766735698_mihome.sqlite file (numbers may be different) and export it.
  • Open this file using a different program, DB Browser for SQLite. Now you can see the deviceID, IP, name and token. This token is encrypted, however. Should be 96 characters.
  • Decrypt token using http://aes.online-domain-tools.com/, instructions image, you should get a 32-character hex value.
  • Use command in terminal: miio tokens update deviceID --token decryptedTokenAsHex
  • miio discover now shows Token: 82a...baa via stored token

you saved me man. thanks. I searched for this token 4 hours.

ghost commented 4 years ago

I'm having trouble connecting to my Aqara hub. I have model number AG005, but whatever I try, I can't seem to connect with it. It doesn't show up in miio discover, even after running an hour. And when I try to use miio inspect <ip> after lookup up it's ip address in the router, it says: WARNING Could not find device I can ping it and whatever just fine, but I can't seem to connect to it using miio in any way, what could I be doing wrong here?

tianzhuang55 commented 4 years ago

I'm having trouble connecting to my Aqara hub. I have model number AG005, but whatever I try, I can't seem to connect with it. It doesn't show up in miio discover, even after running an hour. And when I try to use miio inspect <ip> after lookup up it's ip address in the router, it says: WARNING Could not find device I can ping it and whatever just fine, but I can't seem to connect to it using miio in any way, what could I be doing wrong here?

same problem. Have been successfully before in Homebridge ran in Synology docker, but I uninstall the container, and remake one, now it's unable to discover the miio devices.