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

Tags: #<Tag:0x00007f386d8dd748> #<Tag:0x00007f386d8dd5e0> #<Tag:0x00007f386d8dd400>

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

1 Like

Hi,

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.

1 Like

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 192.168.1.15:4321 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\":\"192.168.1.15\"}"}

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\":\"192.168.1.15\"}"}

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 192.168.1.15:4321 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\":\"192.168.1.15\"}"}

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\":\"192.168.1.15\"}"}

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
网关ID:130080011
Zigbee通道:25
网关信息:
{"life":444998,"cfg_time":0,"token":"18fd8f1ac717e6a28fea65955d8ffef1","mac":"04:CF:??:??:??:??","fw_ver":"1.4.1_161","hw_ver":"MW300","model":"lumi.gateway.v3","mcu_fw_ver":"0143","wifi_fw_ver":"SD878x-14.76.36.p84-702.1.0-WM",
"ap":{"rssi":-40,"ssid":"Fig_Vam","bssid":"bssid"},
"netif":"localIp":"192.168.1.15","mask":"255.255.255.0",
"gw":"192.168.1.1","gw_mac":"mac"},
"mmfree":166000,"ot":"ott",
"otu_stat":[438,404,320,29,239,1069],"ott_stat":[117,4,444,963]}

子设备信息:
[{"model":"lumi.plug.v1","did":"lumi.158d0001e8838c","name":"Mi Smart Plug"},
{"model":"lumi.weather.v1","did":"lumi.158d000273cd11","name":"Temp"},
{"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 ?

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

1 Like

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 !!).

Thanks.

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

FAQ:

  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
3 Likes

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.

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!!

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/

2 Likes

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 ;).

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.

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.

Hi,
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.

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.

I bought my unit on banggood, my friend on the gearbest. The question is not “where” but “when”. You should wait for discounts or sales ;).

Ok, it’s easy to distinguish them. Better buy mijia (in my opinion).

It is not mandatory to sick to stock version. Currently, I’ve the latest version of mi home app on my phone and the latest firmware on the gateway. IMPORTANT: enable development options and “additional communication” before updating the gateway firmware or you will have to disassemble the device and solder things.
If you are afraid of soldering, stay on the default firmware.

1 Like

I have an UART adapter and a soldering iron if I mess stuff up :wink:

So I don’t have to download an old version apk, just go with the recent one and turn in dev mode?

Wow Thanks ! This is the solution !

But sadly some of us aren’t really good at electronic. I clearly prefer the dev.

Thanks for the complete solution.

2 Likes

Stupid question: Do you not need a password from the app?

As far as i know the topic, you should be fine.

Hi,

has anybody tried to downgrade/install firmware via miiocli? All i can achieve is an error and no incoming queries on my http server.

miiocli device --ip 192.168.0.101 --token xxxx raw_command miIO.ota '{"app_url":"http://192.168.0.102/063df95bd538a9cfa22c7c86642cf11e_upd_lumi.gateway.v3.bin","file_md5":"063df95bd538a9cfa22c7c86642cf11e","install":"1","proc":"dnld install","mode":"normal"}'
Running command raw_command
Error: {'code': -5000, 'message': 'invalied'}

miIO.info does work:

miiocli device --ip 192.168.0.101 --token xxxx raw_command miIO.info
Running command raw_command
{'life': 1184, 'cfg_time': 0, 'token': 'xxxx', 'mac': '78:11:DC:xxxx', 'fw_ver': '1.4.1_161', 'hw_ver': 'MW300', 'model': 'lumi.gateway.v3', 'mcu_fw_ver': '0158', [..]}

Is a public ip/specific hostname required for ota?

PS: I tried this in unprovisioned and provisioned mode with internet access and without.