Hi, guys! Can anybody help me with Xiaomi + OH2 connection?
here is what i got after starting:
12:24:08.837 [INFO ] [smarthome.event.ThingAddedEvent ] - Thing 'mihome:bridge:f0b4299aa981' has been added.
12:24:09.136 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at http://192.168.0.100:8080
12:24:09.137 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at https://192.168.0.100:8443
12:24:09.250 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
12:24:09.273 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
12:24:09.306 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
12:24:09.387 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'mihome:bridge:f0b4299aa981' changed from UNINITIALIZED to INITIALIZING
12:24:09.401 [ERROR] [e.internal.socket.XiaomiBridgeSocket] - Setup socket error
java.net.SocketException: Can't assign requested address
at java.net.PlainDatagramSocketImpl.join(Native Method)[:1.8.0_05]
at java.net.AbstractPlainDatagramSocketImpl.join(AbstractPlainDatagramSocketImpl.java:178)[:1.8.0_05]
at java.net.MulticastSocket.joinGroup(MulticastSocket.java:323)[:1.8.0_05]
at org.openhab.binding.mihome.internal.socket.XiaomiBridgeSocket.setupSocket(XiaomiBridgeSocket.java:47)[182:org.openhab.binding.mihome:2.2.0.201707020013]
at org.openhab.binding.mihome.internal.socket.XiaomiSocket.<init>(XiaomiSocket.java:68)[182:org.openhab.binding.mihome:2.2.0.201707020013]
at org.openhab.binding.mihome.internal.socket.XiaomiBridgeSocket.<init>(XiaomiBridgeSocket.java:30)[182:org.openhab.binding.mihome:2.2.0.201707020013]
at org.openhab.binding.mihome.handler.XiaomiBridgeHandler.initialize(XiaomiBridgeHandler.java:99)[182:org.openhab.binding.mihome:2.2.0.201707020013]
at org.eclipse.smarthome.core.thing.internal.ThingManager$9.call(ThingManager.java:741)[105:org.eclipse.smarthome.core.thing:0.9.0.b5]
at org.eclipse.smarthome.core.thing.internal.ThingManager$9.call(ThingManager.java:1)[105:org.eclipse.smarthome.core.thing:0.9.0.b5]
at org.eclipse.smarthome.core.common.SafeMethodCaller$CallableWrapper.call(SafeMethodCaller.java:181)[98:org.eclipse.smarthome.core:0.9.0.b5]
at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_05]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_05]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_05]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_05]
12:24:10.416 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'mihome:bridge:f0b4299aa981' changed from INITIALIZING to ONLINE
I don’t use that module so can’t give specific advice on it but your error message looks like a normal network port or IP address binding style error.
Specifically because it’s talking about sockets I’d dig around port conflicts. On a quick first glance the Xiaomi docs page talks about needing to bind to port 9898, have you checked nothing else is already using that on your system? Something like:
netstat -an
will give you an indication of existing bindings, depending on your OS. But if you Google relevant to your OS platform you’ll get plenty of answers that will guide you to commands or tools that will also identify what service/application already has the port binding.
[17:28:14] $ sudo nmap -sU -p9898 localhost
Password:
Starting Nmap 7.40 ( https://nmap.org ) at 2017-10-25 18:17 EEST
Nmap scan report for localhost (127.0.0.1)
Host is up.
Other addresses for localhost (not scanned): ::1 fe80::1
PORT STATE SERVICE
9898/udp open|filtered monkeycom
Nmap done: 1 IP address (1 host up) scanned in 2.08 seconds
So it does look like a bind issue as you’ve got something running there.
First look around suggested either a very old videophone service or a Virus related to ‘monkeycom’?! But all references are very old and unlikely C&C RATs would use UDP so not convinced on those results which leads me to think maybe nmap is identifying it as the wrong service for you, nmap is often guessing from pattern matches.
Try:
sudo netstat -tulpn
that should return the operating systems real name for the found program/service. Once you have that then you can decide what you want to do about it.
i think lsof -n -i:9898 is the analog for macOS
but it return nothing in terminal…
and the same service on my Xiaomi Gateway too:
[20:39:40] $ sudo nmap -sU -p9898 192.168.0.2
Starting Nmap 7.40 ( https://nmap.org ) at 2017-10-25 20:40 EEST
Nmap scan report for 192.168.0.2
Host is up (0.085s latency).
PORT STATE SERVICE
9898/udp open monkeycom
MAC Address: F0:B4:29:9A:A9:81 (Xiaomi Communications)
Nmap done: 1 IP address (1 host up) scanned in 0.23 seconds
Make sure you run it with sudo: sudo lsof -n -i:9898
otherwise it will return empty.
Looks like your nmap scan of the Xiaomi Gateway proves that it is not ideal at identifying what the name of the service is, still monkeycom. It’s interesting but you need to work out what is running on localhost (192.168.0.100) for the OH server that is having bind problems.
Thanks, for reply!
Very strange things happens
And ONLY after running OH ./start.sh i got this data for 9898 port:
[21:40:38] $ sudo lsof -n -i:9898
Password:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 20868 tirikon 268u IPv6 0x89e9153e3ac0d767 0t0 UDP *:monkeycom
and
[15:44:53] 1 $ sudo nmap -sU -p9898 192.168.0.100
Starting Nmap 7.40 ( https://nmap.org ) at 2017-10-26 15:46 EEST
Nmap scan report for 192.168.0.100
Host is up.
PORT STATE SERVICE
9898/udp open|filtered monkeycom
Nmap done: 1 IP address (1 host up) scanned in 2.11 seconds
and it seems my 9898 port is already used with Xiaomi Gateway, or i don’t know what happens…
[16:15:00] $ sudo tcpdump -A -s0 -ien0 -vv port 9898
tcpdump: listening on en0, link-type EN10MB (Ethernet), capture size 262144 bytes
16:15:26.203730 IP (tos 0x0, ttl 255, id 9855, offset 0, flags [none], proto UDP (17), length 162)
192.168.0.2.rwhois > 224.0.0.50.monkeycom: [udp sum ok] UDP, length 134
E...&..............2..&....O{"cmd":"heartbeat","model":"gateway","sid":"f0b4299aa981","short_id":"0","token":"kDZF74h4aPxT4Sa4","data":"{\"ip\":\"192.168.0.2\"}"}
16:15:36.238705 IP (tos 0x0, ttl 255, id 9856, offset 0, flags [none], proto UDP (17), length 162)
192.168.0.2.rwhois > 224.0.0.50.monkeycom: [udp sum ok] UDP, length 134
E...&..............2..&...9.{"cmd":"heartbeat","model":"gateway","sid":"f0b4299aa981","short_id":"0","token":"cHQRrREBOBvL4A3T","data":"{\"ip\":\"192.168.0.2\"}"}
^C
2 packets captured
1524 packets received by filter
0 packets dropped by kernel
but the port in my laptop is closed…
[16:17:24] $ sudo nmap -sU -p9898 192.168.0.100
Starting Nmap 7.40 ( https://nmap.org ) at 2017-10-26 16:19 EEST
Nmap scan report for 192.168.0.100
Host is up (0.00013s latency).
PORT STATE SERVICE
9898/udp closed monkeycom
Nmap done: 1 IP address (1 host up) scanned in 0.10 seconds
On MacOS in system preferences Security & Privacy you will find the firewall tab. Is that enabled? If yes then a quick test is to turn it off and rerun somes tests:
nmap scan x.100 - should be nothing running
now start OH
nmap scan x.100 - does rescan show something now
If things work better then you can turn the firewall back on and deal with allowing your exceptions.
"On MacOS in system preferences Security & Privacy you will find the firewall tab. Is that enabled? If yes then a quick test is to turn it off and rerun somes tests:"
1.:
[17:31:32] $ sudo nmap -sU -p9898 192.168.0.100
Starting Nmap 7.40 ( https://nmap.org ) at 2017-10-27 17:31 EEST
Nmap scan report for 192.168.0.100
Host is up (0.00010s latency).
PORT STATE SERVICE
9898/udp closed monkeycom
2.:
[17:31:40] $ sudo nmap -sU -p9898 192.168.0.100
Starting Nmap 7.40 ( https://nmap.org ) at 2017-10-27 17:32 EEST
Nmap scan report for 192.168.0.100
Host is up.
PORT STATE SERVICE
9898/udp open|filtered monkeycom
and log from OH:
openhab> Exception in thread "Thread-56" java.lang.IllegalStateException: Not a JSON Object: null
at com.google.gson.JsonElement.getAsJsonObject(JsonElement.java:90)
at org.openhab.binding.mihome.internal.socket.XiaomiSocket$ReceiverThread.receiveData(XiaomiSocket.java:207)
at org.openhab.binding.mihome.internal.socket.XiaomiSocket$ReceiverThread.run(XiaomiSocket.java:187)
log:tail
17:32:33.677 [INFO ] [smarthome.event.ThingAddedEvent ] - Thing 'mihome:bridge:f0b4299aa981' has been added.
17:32:34.119 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at http://192.168.0.100:8080
17:32:34.120 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at https://192.168.0.100:8443
17:32:34.189 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
17:32:34.217 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
17:32:34.237 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
17:32:34.319 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'mihome:bridge:f0b4299aa981' changed from UNINITIALIZED to INITIALIZING
17:32:34.318 [ERROR] [e.internal.socket.XiaomiBridgeSocket] - Setup socket error
java.net.SocketException: Can't assign requested address
...
I might be running to same issue at the moment. I have just started with the latest openhab package and trying to connect Xiaomi Home Gateway.
Running latest High Sierra OSX with Java version “1.8.0_144”. Latest Xiaomi GW version. I’m able to see only battery levels from the Temperature things, but all other information is not visible in Paper UI (showing zero or empty values).
I’m seeing same “[ERROR] [e.internal.socket.XiaomiBridgeSocket] - Setup socket error / java.net.SocketException: Can’t assign requested address” error. Also UDP port is available if OH is down. Shows also name monkeycom.
If there is any debugging tasks, I can try to do those also.
I updated OH mihome bindings jar-file from master-branch manually (https://github.com/openhab/openhab2-addons) and I was able to get monitoring data appearing correctly. The only thing was that the schedule for tracking new values was not working.
Editing OH items configuration, would refresh values from Xiaomi GW again once, but not twice. The OH didn’t sent any more read requests to GW, which I think is the way to get GW to send updates. When I manually edited binding code to sent those read messages in interval way (once per 10 seconds), I was able to get “fresh” data from GW to OH frequently.
It feels now that bindings are failing to keep the correct socket handler and that is the reason why it tries wrongly open the same port again and of course fails. I will continue debugging a bit on this issue still.
I have the same Problem. Bridge is always online, Gateway and everything else isn’t.
Somehow I get Temperature values.
So I don’t get any values either:
.things:
sudo nmap -sU -p9898 localhost
[sudo] password for openhabian:
Starting Nmap 7.40 ( https://nmap.org ) at 2018-10-02 18:11 CEST
Nmap scan report for localhost (127.0.0.1)
Host is up.
Other addresses for localhost (not scanned): ::1
PORT STATE SERVICE
9898/udp open|filtered monkeycom
Nmap done: 1 IP address (1 host up) scanned in 2.60 seconds