[SOLVED] Xiaomi gateway v3 with latest firmware is not communicating properly with openhab

Hi!

I would like to get some help or instructions how can I configure it?
I have received my first gateway 1 month ago, and mi home app offered me to update the firmware (I thought why not…)
It is visible as things and getting the informations from sensors for 2 hours, and after 2 hours all things except bridge become offline, after thing rescan all become online again for another 2 hours. I have enabled wireless communcation protocol in mi home app, get the password and insert developer key to bridge.

Another problem, when I trying to send any command to gateway (like change brightness, etc…) nothing happened. I saw somewhere the gw device should be on same wifi network with openhab server (running on ubuntu linux).
I put a wifi card to server and changed the routing to access gw on wifi card, other communications on LAN card, and I can see the tcpdump traffic, can see the heartbeats too.
In tcpdump I saw: “Invalid key len”

heartbeat tcpdump output:

19:35:11.780534 IP (tos 0x0, ttl 255, id 56888, offset 0, flags [none], proto UDP (17), length 164)
192.168.0.110.4321 > 224.0.0.50.9898: [udp sum ok] UDP, length 136
E…8…;…n…2…&…{“cmd”:“heartbeat”,“model”:“gateway”,“sid”:“7811dcdc2cfc”,“short_id”:“0”,“token”:“iUz1SF18wnyX83IY”,“data”:"{“ip”:“192.168.0.110”}"}

invalid key output:

19:59:15.775170 IP (tos 0x0, ttl 255, id 249, offset 0, flags [none], proto UDP (17), length 109)
192.168.0.110.9898 > nas.9898: [udp sum ok] UDP, length 81
E…m…83…n…&.&…Y.){“cmd”:“write_ack”,“sid”:“7811dcdc2cfc”,“data”:"{“error”:“Invalid key len”}"}

openhab.log:

2018-09-01 20:00:29.278 [WARN ] [g.mihome.handler.XiaomiBridgeHandler] - No token received from the gateway yet. Unable to encrypt the access key.

ps: I have regenereated and changed the password at least 100 times with no luck.

What else informations do you need for debug?

Thanks!
Gabor

Missed 1 thing from tcpdump output, this is the communication when I tried to turn on the gateway light:

20:42:41.419896 IP (tos 0x0, ttl 64, id 18355, offset 0, flags [DF], proto UDP (17), length 148)
nas.9898 > 192.168.0.110.9898: [udp sum ok] UDP, length 120
E…G.@.@.pR…n&.&…Fx{“cmd”: “write”, “model”: “gateway”, “sid”: “7811dcdc2cfc”, “short_id”: “0”, “data”: “{“rgb”: 4026464, “key”: “”}”}
20:42:41.425981 IP (tos 0x0, ttl 255, id 1713, offset 0, flags [none], proto UDP (17), length 109)
192.168.0.110.9898 > nas.9898: [udp sum ok] UDP, length 81
E…m…2{…n…&.&…Y.){“cmd”:“write_ack”,“sid”:“7811dcdc2cfc”,“data”:"{“error”:“Invalid key len”}"}

problem solved. Many people are talked about multicast on local network, so I have checked my secondary router which is closer to xiaomi gateway to enable multicast, this router is acting as range extender. I have found the only multicast option in WAN setup (which is not used on this router), so I have enabled it, restarted and everything is working properly on openhab version 2.3.
I still no have idea why the WAN multicast solved this issue, but I’m happy to finally fixed it after 1 month sleepless nights.

1 Like

OH MY GOD
this issue took me about a half of a year to realize
Thanks alot
Fucking access point blocking off all multicast traffic damn I’m so angry rn

Hi Nico,
I have the same problem but after activating multicast in my router I have the same message:
No token received from the gateway yet. Unable to encrypt the access key.
and I cannot control anything. Did you change other options/configuration?
I’m working under mac.
Thanks.

So you’re Mihome devkey is still valid?
I would try to set the logs in Karaf console of mihome to TRACE, to see every log of the Binding.
Helped me out quite alot. I’ve seen the Code, and it’s pretty stable.
I’ve just denied the MAC address of my OH & the xiaomi gateway, and it’s working pretty fine, since my AP doesn’t support any multicast traffic.

Hi Nico111,

I’ve traced the binding and I cannot see more things…

2018-11-13 10:30:37.083 [DEBUG] [home.handler.XiaomiDeviceBaseHandler] - Device MYID on channel mihome:gateway:MYID:brightness received command ON

2018-11-13 10:30:37.083 [WARN ] [g.mihome.handler.XiaomiBridgeHandler] - No token received from the gateway yet. Unable to encrypt the access key.

2018-11-13 10:30:37.085 [DEBUG] [g.mihome.handler.XiaomiBridgeHandler] - Send to bridge mihome:bridge:MYID: {“cmd”: “write”, “model”: “gateway”, “sid”: “MYID”, “short_id”: “0”, “data”: “{“rgb”: 1694498815, “key”: “”}”}

2018-11-13 10:30:37.086 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Sending message: {“cmd”: “write”, “model”: “gateway”, “sid”: “MYID”, “short_id”: “0”, “data”: “{“rgb”: 1694498815, “key”: “”}”} to /192.168.1.36:9898

2018-11-13 10:30:37.088 [DEBUG] [me.handler.XiaomiActorGatewayHandler] - Update ON for channel mihome:gateway:MYID:brightness received

2018-11-13 10:30:37.091 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.1.36:9898 on Port 9898

2018-11-13 10:30:37.091 [TRACE] [g.mihome.handler.XiaomiBridgeHandler] - Received message {“cmd”:“write_ack”,“sid”:“MYID”,“data”:"{“error”:“Invalid key len”}"}

2018-11-13 10:30:37.091 [TRACE] [g.mihome.handler.XiaomiBridgeHandler] - Updated “last time seen” for device MYID

2018-11-13 10:30:37.092 [DEBUG] [g.mihome.handler.XiaomiBridgeHandler] - Device MYID honored write request

2018-11-13 10:30:37.093 [DEBUG] [home.handler.XiaomiDeviceBaseHandler] - Item got update: {“cmd”:“write_ack”,“sid”:“MYID”,“data”:"{“error”:“Invalid key len”}"}

2018-11-13 10:30:37.093 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners

2018-11-13 10:30:37.093 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-40,5,main] waiting for data on port 9898

2018-11-13 10:31:27.586 [DEBUG] [home.handler.XiaomiDeviceBaseHandler] - Device MYID on channel mihome:gateway:MYID:brightness received command OFF

2018-11-13 10:31:27.586 [WARN ] [g.mihome.handler.XiaomiBridgeHandler] - No token received from the gateway yet. Unable to encrypt the access key.

2018-11-13 10:31:27.587 [DEBUG] [g.mihome.handler.XiaomiBridgeHandler] - Send to bridge mihome:bridge:MYID: {“cmd”: “write”, “model”: “gateway”, “sid”: “MYID”, “short_id”: “0”, “data”: “{“rgb”: 16777215, “key”: “”}”}

2018-11-13 10:31:27.589 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Sending message: {“cmd”: “write”, “model”: “gateway”, “sid”: “MYID”, “short_id”: “0”, “data”: “{“rgb”: 16777215, “key”: “”}”} to /192.168.1.36:9898

2018-11-13 10:31:27.590 [DEBUG] [me.handler.XiaomiActorGatewayHandler] - Update OFF for channel mihome:gateway:MYID:brightness received

2018-11-13 10:31:27.594 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.1.36:9898 on Port 9898

2018-11-13 10:31:27.595 [TRACE] [g.mihome.handler.XiaomiBridgeHandler] - Received message {“cmd”:“write_ack”,“sid”:“MYID”,“data”:"{“error”:“Invalid key len”}"}

2018-11-13 10:31:27.595 [TRACE] [g.mihome.handler.XiaomiBridgeHandler] - Updated “last time seen” for device MYID

2018-11-13 10:31:27.596 [DEBUG] [g.mihome.handler.XiaomiBridgeHandler] - Device MYID honored write request

2018-11-13 10:31:27.596 [DEBUG] [home.handler.XiaomiDeviceBaseHandler] - Item got update: {“cmd”:“write_ack”,“sid”:“MYID”,“data”:"{“error”:“Invalid key len”}"}

2018-11-13 10:31:27.596 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners

2018-11-13 10:31:27.597 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-40,5,main] waiting for data on port 9898

I had this error when my AP was blocking all multicast packets off.

Already tried a TCPdump? probably will help you indicate if the correct json data is arriving the raspberry port.
But I had exactly the same errors and I really thing that multicast traffic is still blocked off in your network.

You can try to enable it in your firewall too.

I’ve tried to enable multicast in my router with high priority:

and also disable firewall

and doing the same with WAN

21

But it’s happening the same there is somewhere can i enable multicast?

I don’t know sadly.
I’m sorry, I don’t have the same router.
You can ban the MAC Address of your OpenHAB server.
A Workaround but solves the problem …

Hi all… is a little fustrating trying to make this working… first the 9898 port closed, and now problems with multicas…
I have, I think, the same problem, but not exactly the same. I have OpenHab over a Windows 10 computer, Xiaomi Gateway v3 with latest firmware. Checking some router configurations, I have seen with Wireshark that with some configurations, multicast packets from Xaiomi Gateway (destination IP: 224.0.0.50, port 4321 to 9898) are arriving to the computer… but only are seen with network card in promiscuous mode, not in “normal mode”, so OpenHab aren’t receiving the packets.
Anyone with this issue?

Thanks in advance.

I have checked again, and hearbeart UPD packets are arriving in normal mode also (not only promiscuous), but Xiaomi Binding aren’t reading it.

Well, searching it seems an old issue and not only related to Windows… I tried some network adapter routing solutions, but doesn’t work.
There are any advance on this issue?

Thanks.
Ruben

Hi,

I have kind of the same problem. I have Xiaomi lumi-gateway-v3 and Openhabian on rpi3. Installed the Xiaomi Smart Home Binding and managed to connect the device with the Xiaomi App and get the token and developer key. My problem is that when i auto search for it in OH nothing is found.

This is from the log of OH:
2019-07-14 10:23:25.471 [WARN ] [core.thing.internal.ThingManagerImpl] - Disposing handler for thing ‘miio:unsupported:04FF6428’ takes more than 5000ms.

2019-07-14 10:23:25.489 [hingStatusInfoChangedEvent] - ‘miio:unsupported:04FF6428’ changed from UNINITIALIZED to UNINITIALIZED (HANDLER_MISSING_ERROR)
2019-07-14 12:47:35.627 [hingStatusInfoChangedEvent] - ‘mihome:bridge:26c1fb9f’ changed from INITIALIZING to OFFLINE

I’m an OpenHab2 rookie so forgive me if im asking a dumb question. I followed this guide https://www.openhab.org/addons/bindings/mihome/
but came short when i had to autofind it in OH.

Tanks for the help in advance!

some1?