[SOLVED] Openhab2 - Xiaomi Mi Gateway - does not respond

  • Platform information:
    • Hardware: CPU: armv7l / ram: 1gb / sd card: 8gb
    • OS: Linux 3.10.107-11; Ubuntu 18.04.1 LTS bionic
    • Java Runtime Environment: OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-0ubuntu0.18.04.1-b13)
    • openHAB version: OpenHab 2.3.0 (tested on 2.4.0M4)

Hello,

i’ve problem with connection to my Xiaomi Mi Gateway (Original Xiaomi Mijia Upgrade Version Smart Home). I’ve followed steps in documentation (https://www.openhab.org/addons/bindings/mihome/#setup). I’ve enabled ‘wireless communication protocol’ and save password to gateway using Mi Home Android App (and also i’ve confirmed it using “ok” button). I’ve installed mihome binding through paperUI in my openhab server.
I’ve enabled trace logs in openhab and this is all i’ve got there:

[...]
2018-10-04 02:08:09.444 [DEBUG] [g.mihome.handler.XiaomiBridgeHandler] - Having 1 Item Discovery listeners
2018-10-04 02:08:09.449 [DEBUG] [org.openhab.binding.mihome          ] - ServiceEvent REGISTERED - {org.eclipse.smarthome.config.discovery.DiscoveryService}={service.id=301, service.bundleid=221, service.scope=singleton} - org.openhab.binding.mihome
2018-10-04 02:08:09.459 [DEBUG] [org.openhab.binding.mihome          ] - ServiceEvent REGISTERED - {org.eclipse.smarthome.config.core.status.ConfigStatusProvider}={service.id=302, service.bundleid=221, service.scope=singleton} - org.openhab.binding.mihome
2018-10-04 02:08:09.505 [DEBUG] [g.mihome.handler.XiaomiBridgeHandler] - Init socket on Port: 9898
2018-10-04 02:08:09.517 [DEBUG] [e.internal.socket.XiaomiBridgeSocket] - Setup socket
2018-10-04 02:08:09.520 [DEBUG] [e.internal.socket.XiaomiBridgeSocket] - Initialized socket to null:-1 on 0.0.0.0/0.0.0.0:9898
2018-10-04 02:08:09.525 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - There are 1 open sockets: {9898=java.net.MulticastSocket@dd837}
2018-10-04 02:08:09.525 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Staring reveicer thread for socket on port 9898
2018-10-04 02:08:09.529 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-39,5,main] waiting for data on port 9898
2018-10-04 02:08:09.529 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Adding socket listener org.openhab.binding.mihome.handler.XiaomiBridgeHandler@65816f
2018-10-04 02:08:10.164 [WARN ] [e.jetty.util.thread.ThreadPoolBudget] - Low configured threads: (max=8 - required=1)=7 < warnAt=8 for QueuedThreadPool[ServletModel-21]@1cddca7{STARTING,8<=0<=8,i=0,q=0}[ReservedThreadExecutor@17d35ec{s=0/1,p=0}]
2018-10-04 02:08:10.537 [DEBUG] [g.mihome.handler.XiaomiBridgeHandler] - Triggered discovery
2018-10-04 02:08:10.541 [DEBUG] [g.mihome.handler.XiaomiBridgeHandler] - Send to bridge mihome:bridge:04FCFFFF: {"cmd": "get_id_list"}
2018-10-04 02:08:10.544 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Sending message: {"cmd": "get_id_list"} to /192.x.x.x:9898
[...]

And thats all… there is no response…

My openhab server and xiaomi mi gateway are in the same network, i’ve disabled all firewalls (switch to ACCEPT on all policies in iptables). No matter if i turn on ‘wireless communication protocol’ or not this is my nmap scanning result:

# nmap -sU -p 5353,54321,9898 openhab-server

Starting Nmap 7.60 ( https://nmap.org ) at 2018-10-04 07:15 CEST
Nmap scan report for 192.x.x.x
Host is up (0.059s latency).

PORT      STATE         SERVICE
5353/udp  open|filtered zeroconf
9898/udp  closed        monkeycom
54321/udp open|filtered bo2k
MAC Address: 78:11:00:00:00:00 (Xiaomi Electronics,co.)

Nmap done: 1 IP address (1 host up) scanned in 2.60 seconds

All other ports are closed.
I’ve got same results on openhab 2.3 and 2.4.0M4 version. I can’t open the 9898 port on xiaomi gateway. I’ve started tcpdump on my wifi-router and i’ve discovered that android mi home app doesn’t use this port at all. All communication is through udp port 54321.

When i’m tring to use “autodiscovery” function in paperUI i’ve got only “Xiaomi Mi IO Device 04FC____ (8364____) lumi-gateway-v3_miio8364____” which is correct but this message came from miio add-on (which is used for my xiaomi air purifier) not for mihome add-on. Miio doesn’t support Xiaomi Gateway and only can display if it’s turn on or off. It discovers it as miio:unsupported:04FC____. I’ve tried to completly remove “miio” addon and this didn’t help.

This is from “about tab” from my Xiaomi Mi Gateway downloaded by Android app:

Version code:201
网关ID:8364____
Zigbee通道:15
网关信息:
{"life":19371,"cfg_time":0,"token":"3___________759_______6_______07","mac":"78:11:__:__:__:__","fw_ver":"1.4.1_157","hw_ver":"MW300","uid":17592_____,"model":"lumi.gateway.v3","mcu_fw_ver":"0143","wifi_fw_ver":"SD878x-14.76.36.p84-702.1.0-WM","ap":{"rssi":-69,"ssid":"______________","bssid":"_________________"},"netif":{"localIp":"192.____.___","mask":"255.255.255.0","gw":"192.__.__.___","gw_mac":"__:__:__:__:__:__"},"mmfree":170224,"ot":"otu","otu_stat":[259,230,304,22,281,9040],"ott_stat":[0,0,0,0]}

In the end i would like to write that gateway works fine using android app and connects to 3 sensor without any problems. Why I my gateway doesn’t respond? What am I doing wrong? Do I have not supported device or too new firmware? How can i downgrade it?

Other config files:

gateway.items

Bridge mihome:bridge:04FC____ "Xiaomi Gateway" [ serialNumber="8364____", ipAddress="192.x.x.x", port=9898, key="____________", pollingInterval=600  ] {
Things:
    gateway    7811dc______    "Xiaomi Mi Smart Home Gateway"    [itemId="7811dc______"]
}

gateway.items

Switch Gateway_AddDevice { channel="mihome:gateway:7811dcf79144:joinPermission" }
Switch Gateway_LightSwitch <light> { channel="mihome:gateway:7811dcf79144:brightness" }
Dimmer Gateway_Brightness <dimmablelight> { channel="mihome:gateway:7811dcf79144:brightness" }

gateway.sitemap

sitemap xiaomi_test label="Testing Xiaomi" {
        Frame label="Gateway" {
                Switch item=Gateway_AddDevice label="Add device"
                Switch item=Gateway_LightSwitch label="Turn on"
        }
}
1 Like

Unfortunately I have exactly the same problem than yours.
Impossible to open the 9898 port. Did you find any solution to open it or downgrade the firmware?

Did you find any solution to open it or downgrade the firmware?

We probably won’t be able to open this port. The “Upgraded version of Xiaomi Gateway” uses new protocol to communicate (the same protocol which it’s used by Xiaomi Purifier and Vacuum). We can’t use mihome addon.

This was bad news, good news is… there is a “miio” addon (for purifier and vacuum communication), it has implementation for the “newer” protocol (encryption and other stuff). Currently I’m trying to extend this addon to handle Xiaomi Gateway. I have some prototype code and I can control light color, volumes of radio and other basic stuff. I don’t have too much time but when i will have something working I will try put a pull request for the repo of miio addon.

I’m not experienced openhab developer so I will have problem with adding support for “slave” devices (temperature sensor, motion and door/window sensor) so I can’t promise that i will implement all functionality of android/iphone “mi home app”.

If you are interested you can check this repo: https://github.com/aholstenson/miio . This guy implemented almost all functionality but in javascript/typescript (not all is working for me, but it’s valuable source of information for me).

Thank you for the response, I’ll take a look but it’s still very frustrating :wink:

Hey,
I’m having the same problem since half a year now and it’s driving me nuts.
Let’s figure this out all together.

I’m new to wireshark and can’t really detect any packages from the Gateway, can you help me out here?
Have you tried to change the port of the xiaomi bridge config?

I would try myself but I’m new to wireshark and can’t really detect any packages from the Gateway, can you help me out here?

maybe the same problem here /subscribing to the thread

So I got a bit into sniffing my network, made a router tcp dump and found this.
I guess the gateway wants to send data to port 9898, which is blocked by monkeycom.
I’m not quite sure if I’m interpreting this right.
Do we have any wireshark users here?

You probably running wireshark on your computer and not on wifi router. I usually run tcpdump on my wifi router and save output in file. Next I copy output file to my computer and I’m view it by wireshark. If you don’t have possibility to run custom programs on your router, there is a technique called “arp poissoning” BUT BE AWARE this is offensive/aggressive technique. You need to be sure that are you doing and you need to be the owner of local network where you executing this technique (because you can disturb working whole network).

Yes, gateway is trying to do this but its rwhois protocol and probably its some kind of dns operation. I was nothing to do with working with sensor and other xiaomi gateway stuff. As you can see xiaomi gateway uses port 4321, so the gateway port 9898 is still closed. I don’t know if there is point for debuging port 9898. I think they changed protocol and stop using it. If you are interested i thing there is good explanation: http://docs.opencloud.aqara.cn/en/development/gateway-LAN-communication/
but as i said it’s deprecated. Now we need to focus on port 54321, because there is a lot of communication.

lol

  • Yeah I was thinking that too, found some other packages which are indeed running on port 54321 and goes to 8053

Thanks for the hint, I’m of course aware of this and only using my tcpdump on my own network, every person (aka my family) knows this.

Some news:
Iv’e found some sensor data in the TCPdump, and I don’t know why but the protocol “rhwois” actually transfers the Data to Port 9898, so I’m assuming, that port 9898 is STILL responsible for data exchange:
image
And I’ve found a error on the TTL block:


But it’s beeing obviously blocked by monkeycom.

All my sensors worked 2 weeks ago, when I made a Firewallexception for port 9898. They suddenly stopped working, but I don’t think there has been a Gateway update 2 weeks ago or am I wrong?

Very interesting observation. What version of firmware do you have? Because I could sniff that kind of communication.

{ “cmd”: “report”, “model”:… }

I looks like aqara protocol just from documentation. Maybe you have different problem? Can you post picture of your gateway?

fw_ver: 1.4.1_157, mihome Plug-In Vers. 2.61.3

lumi.gateway.v3, this one:

Does other Gateways have different protocols?
I quess that’s standard JSON lol

Let me know if you need some other details too!

I have the same version and same issue :frowning:

There are alot of guys having the same issue, Hope we can all unite to find a solution, or at least the problem causing this.

It’s not relevant btw, Gateway sends those packages to the 224.0.0.50 which is a Unicast adress of your network and every Client/Server receives it

I’m not able to capture any of those unicast packages, but i can capture udp packages flying on port 54321… so I assume Gateway changed protocol… of course it is only my suspicion…

Those are packages flying to the own Xiaomi Cloud, I guess.
They go from port 54321 to port 8053 (senomix)
https://www.senomix.com/
Can’t really tell what that is, but I assuming that there goes our data into a Cloud DB.

I’ve forked openhab2 project and applied my patch with very basic support of xiaomi gateway function. There is no sensor reading, only turning off/on led and controlling volumes.

At the end of README.md there is section with examples for (items, thing and sitemap).

If you don’t have maven and java and still want to try use this addon, you can download it from here.

I’m using the Mi IO binding to control my vacuum.
But I’m not going to use it for the smarthome binding, everything worked just absolute fine and It’s way more supported.
I’ve contacted the contributor of the xiaomi smarthome binding.
When there is someone knowing the answer, he’ll be the one.