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

Tags: #<Tag:0x00007f0147bd7dc0> #<Tag:0x00007f0147bd7c80> #<Tag:0x00007f0147bd7b40>

(Aaron) #103

Hi @Andreas_J, just clarifying your questions (quick summary). There appears to be two modes of operation for these gateways. It doesn’t appears possible for a device to go from mode 2 to mode 1.

Mode 1 (working): The gateway has port 9898 open. The gateway occasionally sends a broadcast message to In addition whenever something happens (motion detected or switch pressed for example) a broadcast message is sent.
The most important thing is that the broadcast messages are sent in this mode of operation. The reason I’ve suggested to check port 9898 is just because it is an easy way to diagnose which mode the gateway is in (seems to reliably indicate which mode).

Mode 2 (not working): The gateway’s port 9898 is mostly closed (sometimes it appears to be open when configuring the gateway). No multicast messages are sent. Port 54321 is open (MIIO protocol) which allows you to send messages to the device, but does not allow the gateway to send asynchronous messages when events occur.

(A R ) #104

Hi! So, is it 100% safe to upgrade gateway with square text?

By the way, does anybody have an official changelog for 1.4.1_161 version?


(Aaron) #105

There has been at least 2 other reports of it working OK on 161. In addition, my second unit from Gearbest has the square text and it is working correctly (on 161).

(Sour Gelockte) #106

Hey i got a gateway from gearbest on black friday. It has the round text.
Running the latest firmware , developer mode switched on after firmware update.
Only ports that are open are 5353 & 54321…
Hope we can figure this out!

(Floyd) #107

Round text 1.4.1_161

5353/udp open|filtered zeroconf
9898/udp closed monkeycom
54321/udp open|filtered bo2k
MAC Address: 28:6C:07:F0:FE:67 (Xiaomi Electronics,co.)

Tried everything, can’t get the 9898 port to open…

Bridge goes offline
(Iznogoud Littleman) #108

Hi everyone,

I’ve buy my gateway in gearbest in October (Round text). I’ve made the update to version 161 and then I’ve activate the dev mode. Gateway not working. Port 9898 closed.

Here info :

Version code:213

Hope we will find a way to make it work. Nobody have new info yet ?

(Leong Walter) #109

Hi all, I have same gateway issue as you are. but good news is, it is work in Domoticz. So I think it is not hardware issue, I guess is the OH binding problem.
I am prefer OH than Domoticz, so hope that it can solve in OH.
btw my gateway version is latest update in dec 2018, 1.4.1-161.0143

(Alexis) #110


As said above, my first gateway updated to FW _161 is not working with OH, I was not sure when I activated the developer mode : before or after updating the firmware to _161… but now I’m pretty sure it was after

I’ve received yesterday a new Gateway, still round text, stock firmware is 1.4.1_150. I did not upgrade the firmware and my gateway is working : nmap show ports 4321 and 9898 opened right after activating the developer/lan mode.
OH discovered my gateway, I’m now in the process to add my sensors.

Hope my first GW will somehow be able to work in a future update from xiaomi.
By the way ; did someone tried to notify Xiaomi of this issue ? will try to fill a request via their app to see if they respond… not very likely but let’s give it a try…

Maybe we could update the Xiaomi Binding add-ons documentation to remove the instruction to update to latest firmware as every new comer to this will face the same issue.

(Konsts) #111

Hello! I have a problem with the work of Xiaomi Bridge. Il.p normally connects and works for some time (and sensors too), but after an hour or more it goes offline.
To return it online, you must restart OpenHub or turn off/on the Thing in PaperUI.

heartbeat every 10 seconds in log:

2018-12-31 02:27:46.269 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-2946,5,main] waiting for data on port 9898

2018-12-31 02:27:56.234 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from on Port 9898

2018-12-31 02:27:56.236 [TRACE] [internal.handler.XiaomiBridgeHandler] - Received message {"cmd":"heartbeat","model":"gateway","sid":"04cf8c744c39","short_id":"0","token":"BIMZCMeHa1XixHt7","data":"{\"ip\":\"\"}"}

2018-12-31 02:27:56.240 [TRACE] [internal.handler.XiaomiBridgeHandler] - Updated "last time seen" for device 04cf8c744c39

2018-12-31 02:27:56.246 [DEBUG] [internal.handler.XiaomiBridgeHandler] - Cancelled running timer

2018-12-31 02:27:56.249 [DEBUG] [rnal.handler.XiaomiDeviceBaseHandler] - Item got update: {"cmd":"heartbeat","model":"gateway","sid":"04cf8c744c39","short_id":"0","token":"BIMZCMeHa1XixHt7","data":"{\"ip\":\"\"}"}

2018-12-31 02:27:56.253 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners

2018-12-31 02:27:56.255 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-2946,5,main] waiting for data on port 9898

Last heartbeat and bridge goes offline:

018-12-31 02:28:06.219 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from on Port 9898

2018-12-31 02:28:06.222 [TRACE] [internal.handler.XiaomiBridgeHandler] - Received message {"cmd":"heartbeat","model":"gateway","sid":"04cf8c744c39","short_id":"0","token":"s3CdI0MhyLiaw5Lj","data":"{\"ip\":\"\"}"}

2018-12-31 02:28:06.225 [TRACE] [internal.handler.XiaomiBridgeHandler] - Updated "last time seen" for device 04cf8c744c39

2018-12-31 02:28:06.231 [DEBUG] [internal.handler.XiaomiBridgeHandler] - Cancelled running timer

2018-12-31 02:28:06.234 [DEBUG] [rnal.handler.XiaomiDeviceBaseHandler] - Item got update: {"cmd":"heartbeat","model":"gateway","sid":"04cf8c744c39","short_id":"0","token":"s3CdI0MhyLiaw5Lj","data":"{\"ip\":\"\"}"}

2018-12-31 02:28:06.238 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners

2018-12-31 02:28:06.240 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-2946,5,main] waiting for data on port 9898

==> /var/log/openhab2/events.log <==

2018-12-31 02:33:06.249 [hingStatusInfoChangedEvent] - 'mihome:bridge:04cf8c744c39' changed from ONLINE to OFFLINE

2018-12-31 02:33:06.264 [hingStatusInfoChangedEvent] - 'mihome:sensor_weather_v1:158d000273cd11' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)

2018-12-31 02:33:06.272 [hingStatusInfoChangedEvent] - 'mihome:gateway:4cf8c744c39' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)

2018-12-31 02:33:06.278 [hingStatusInfoChangedEvent] - 'mihome:sensor_magnet_aq2:158d000276c39f' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)

2018-12-31 02:33:06.283 [hingStatusInfoChangedEvent] - 'mihome:86sw2:158d0002b49c8a' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)

2018-12-31 02:33:06.293 [hingStatusInfoChangedEvent] - 'mihome:sensor_plug:158d0001e8838c' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)

2018-12-31 02:33:06.299 [hingStatusInfoChangedEvent] - 'mihome:sensor_motion_aq2:158d0002b7641a' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)

2018-12-31 02:33:06.306 [hingStatusInfoChangedEvent] - 'mihome:gateway:04cf8c744c39' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)

Bridge info:

Version code:213

[{"model":"lumi.plug.v1","did":"lumi.158d0001e8838c","name":"Mi Smart Plug"},
{"model":"lumi.sensor_magnet.aq2","did":"lumi.158d000276c39f","name":"Aqara Door and Window Sensor"},
{"model":"lumi.remote.b286acn01","did":"lumi.158d0002b49c8a","name":"Switch"},{"model":"lumi.sensor_motion.aq2","did":"lumi.158d0002b7641a","name":"Aqara Motion Sensor"}]

It’s new Gateway, still round text on last firmware.
My latest record is 29 hours online

Any ideas ?

(Sergey M) #112

My English is very bad, so I’ll provide a link to the original (Russian).

(Romain ALCARAZ) #113

Hi guys !

Same problem : I have Mi home gateway v2 (with mijia logo (not aqara)).
My fw version : 1.4.1_161

If domoticz still working with same fw of gateway, someone to update openhab mihome binding ?

And, the documentation page has to be fixed (nos latest firmware please !!).


(Rsx2007) #114

well, tried to set param network.open_pf to 3 - it helped me!
Can see gateway in openhab, iobroker and 9898 port is opened.


  1. Find specific screw bit like fork to open gateway case.
  2. Find UART cable/board.
  3. Solder 3 wires GND and RX / TX like here (Image.
  4. Disconnect RX wire from UART module.
  5. Dont connect Vcc (power) from UART to gateway.
  6. Turn on gateway (220V).
  7. Open putty application, connect to serial port (COM1-30) -select yours one0.
  8. Wait for fully load of gateway, connect RX wire to UART.
  9. You will see all messages of gateway.
  10. Send command psm-set network.open_pf 3, send it few time in case it was spammed by gateway and it can be lost in msgs…
  11. Check your param by command psm-get network.open_pf to be sure its OK.
  12. Turn off gateway.
  13. Turn it ON.
  14. Check your port.
  15. Say thx to this guy - ds2003

(Wojciech F) #115

YES, YES, YES… it works. After this procedure the port 9898 is open. I don’t have time to setup openhab2 but if it works with openhab2 I’m owed you a beer (@rsx2007 ds2003, pm me for paypal/revolut account). :smiley:

One note, I would NOT recommend mixing 230V and uart from usb port. I was able to set this uart command without connecting to 230 V. You need to solder one more pad but you are safer.

Thx one more time.

(Rsx2007) #116

that’s why i said to NOT connect Vcc (power) pin, and there is a chance to broke gateway.
DO NOT CONNECT 5V power pin from UART to gateway!!

(Dennis Giese) #117

Just found this thread. I am the guy who has rooted all Xiaomi/Lumi stuff. Any particular questions/problems?
You find a lot of material here: https://github.com/dgiese/dustcloud-documentation
You can watch my Defcon talk if you want to know how to modify the Gateway Firmware (v3= Cortex M, the newer ones are running Linux). The links can be found here: http://dontvacuum.me/

(Wojciech F) #118

Hi, @dgiese, some of us know who you are. Earlier in this thread I mentioned about you and linked to your materials. A few months ago I exchanged a few e-mails with you.
Thanks to you, I was able to download several firmwares version on the disk and “unpack” them. If you want I could push them to your github repository?
Based on your materials, I was able to obtain a key encrypting communication with the xiaomi cloud. It was fun. How much work it would take the to reverse engineering firmware and determine the algorithm on the basis of which the key is generated? Patching all firmwares version by nexmon is quite tiring and requires time and huge knowledge. People who did not enable “development option” by the andoid/ios app and they upgraded the gateway to the version above 151, actually got stuck and without basic technical skills they can’t to turn it back on. Maybe it would be nice if we could (in the future) create some method of flashing or setting the network.openpf flag in a software only way.

Currently, the problem has been solved thanks to the @rsx2007 (but it requires special screwdriver and basic soldering skills). The last thing we have to do, is update the wiki page about openhab support for xiaomi.

Yes, it’s true. The uart in xiaomi gateway is in 3.3 V standard ;).

(Dennis Giese) #119

Great. Would be also cool if you could write a wiki entry on dustcloud repo. I am at the moment busy with creating an easy root for the new Aqara gateways.

I plan to create a more general way to build custom gateway firmwares… Similar to https://dustbuilder.xvm.mit.edu (for the vacuums).

The gateway firmware has apparently some undocumented commands enabling to modify the psm memory. That could enable to solve your problem with setting the flag

About the keys: the device key is generated in the factory randomly. The entropy looks good, as far as I can tell. Xiaomi messed up the entropy for the token, to it’s brute forceable for many devices. Not sure about the Cortex M gateways tho.

To be honest, I did not do much work on the Gateways in the last time, as I moved to the new Aqara gateways. They run Linux and are way more simpler to modify. Same applies to the Gateway Camera.

I might make a mod to change the identity from lumi.gateway.v3 to the Aqara gateways, as the commands are absolutely the same (except for some special commands). That way the gateways should work on the EU and Asia/US servers.

(Rsx2007) #120

Hi there!

  1. You mean aqara camera gateway?
    I have one, but for now its useless because it doesnt support lumi protocol (or maybe disabled on purpose?). Is there is a chance to upgrade it to classic gateway or eu version of aqara gw?
    Csn test it if needed.

(Dennis Giese) #121

The Aqara Camera Gateway (https://github.com/dgiese/dustcloud-documentation/tree/master/lumi.camera.aq1) uses the same protocol as all other Miio/Miija enabled devices. It behaves like a normal Gateway, except it has additional commands regarding the camera stuff.

(Johannes Gedicke) #122

Hello guys,
this might be a bit off topic, but:
I want to buy a new xiaomi gateway. Where is the best place to buy it… and what do I have to do to set it up and don’t mess up stuff?
I checked for a shop selling the Mijia, not the Aqara version.
Also I read that I should use an old version of the Mi Home App. And that the stock FW have to be at a certain low level.