miio icon indicating copy to clipboard operation
miio copied to clipboard

Device can not be discovered

Open aholstenson opened this issue 6 years ago • 42 comments

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

aholstenson avatar Jan 23 '18 17:01 aholstenson

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?

jghaanstra avatar Jan 23 '18 20:01 jghaanstra

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?

joiglifberg avatar Jan 23 '18 21:01 joiglifberg

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

jghaanstra avatar Jan 23 '18 21:01 jghaanstra

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

aholstenson avatar Jan 24 '18 05:01 aholstenson

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.

joiglifberg avatar Jan 24 '18 07:01 joiglifberg

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

aholstenson avatar Jan 24 '18 08:01 aholstenson

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.

jghaanstra avatar Jan 24 '18 09:01 jghaanstra

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

pkol avatar Feb 27 '18 18:02 pkol

@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 avatar Mar 04 '18 23:03 thorn0

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:

  • Where miio discover didn't work: Win 7 x64, node 9.5.0
  • Where it worked: Win 8.1 x32, node 9.4.0, same network

thorn0 avatar Mar 05 '18 00:03 thorn0

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

pkol avatar Mar 06 '18 22:03 pkol

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

  • miio 0.15.6 (Node 6.10.2)
  • mirobo, version 0.3.9 (Python 3.6.1)

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

nzhou avatar Apr 02 '18 15:04 nzhou

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

rytilahti avatar Apr 02 '18 17:04 rytilahti

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: <Buffer ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +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: <Buffer ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +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: <Buffer ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +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: <Buffer 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> +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: <Buffer ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff> +505ms

lyance avatar Apr 28 '18 03:04 lyance

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

lyance avatar Apr 28 '18 08:04 lyance

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

WKatGitHub avatar May 30 '18 09:05 WKatGitHub

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.

Dmurph24 avatar Jul 16 '18 19:07 Dmurph24

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

pedrommvv avatar Nov 03 '18 00:11 pedrommvv

  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

studentIvan avatar Jan 12 '19 10:01 studentIvan

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?

jezzaaa avatar Feb 17 '19 04:02 jezzaaa

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)

studentIvan avatar Feb 17 '19 17:02 studentIvan

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?

jezzaaa avatar Feb 18 '19 01:02 jezzaaa

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

Have you tried to delete the original app before?

studentIvan avatar Feb 19 '19 20:02 studentIvan

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 avatar Feb 19 '19 23:02 jezzaaa

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.

jezzaaa avatar Feb 20 '19 10:02 jezzaaa

@jezzaaa didn't work what exaclty?

studentIvan avatar Feb 21 '19 12:02 studentIvan

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!

jezzaaa avatar Feb 21 '19 12:02 jezzaaa

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

studentIvan avatar Feb 21 '19 20:02 studentIvan

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 avatar Feb 22 '19 00:02 jezzaaa

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

jezzaaa avatar Feb 22 '19 00:02 jezzaaa