Bluebie / homebridge-miio

Xiaomi Mi Home Plugin for Homebridge
112 stars 26 forks source link

0.2.1 causes EADDRINUSE conflict with homebridge-aqara #16

Closed fxdpz closed 7 years ago

fxdpz commented 7 years ago

after update to 0.2.1, homebridge-miio stop working. log is as followed: [4/21/2017, 9:18:20 AM] Loaded plugin: homebridge-aqara [4/21/2017, 9:18:20 AM] Registering platform 'homebridge-aqara.AqaraPlatform' [4/21/2017, 9:18:20 AM] --- [4/21/2017, 9:18:21 AM] Loaded plugin: homebridge-miio [4/21/2017, 9:18:21 AM] Registering platform 'homebridge-miio.XiaomiMiio' [4/21/2017, 9:18:21 AM] --- [4/21/2017, 9:18:21 AM] Loaded plugin: homebridge-yeelight [4/21/2017, 9:18:21 AM] Registering platform 'homebridge-yeelight.yeelight' [4/21/2017, 9:18:21 AM] --- [4/21/2017, 9:18:21 AM] Loaded config.json with 0 accessories and 1 platforms. [4/21/2017, 9:18:21 AM] --- [4/21/2017, 9:18:21 AM] Loading 1 platforms... [4/21/2017, 9:18:21 AM] Initializing AqaraPlatform platform... Load homebridge-miio.XiaomiMiio [4/21/2017, 9:18:21 AM] [homebridge-miio.XiaomiMiio] Setting up Miio platform Load homebridge-yeelight.yeelight [4/21/2017, 9:18:21 AM] [homebridge-yeelight.yeelight] YeePlatform Init Scan this code with your HomeKit App on your iOS device to pair with Homebridge:

┌────────────┐     
│ 111-11-111 │     
└────────────┘     

[4/21/2017, 9:18:21 AM] [homebridge-miio.XiaomiMiio] DidFinishLaunching [4/21/2017, 9:18:21 AM] [homebridge-yeelight.yeelight] DidFinishLaunching [4/21/2017, 9:18:22 AM] Aqara server is listening on port 9898. [4/21/2017, 9:18:22 AM] Homebridge is running on port 51825. add to multicast group listen on 0.0.0.0 no did or loc found! [4/21/2017, 9:18:22 AM] [homebridge-miio.XiaomiMiio] device discovered 56290892 [4/21/2017, 9:18:22 AM] [homebridge-miio.XiaomiMiio] Investigating Miio Device at udp://192.168.1.11:54321 [4/21/2017, 9:18:22 AM] [homebridge-miio.XiaomiMiio] device discovered 48618067 [4/21/2017, 9:18:22 AM] [homebridge-miio.XiaomiMiio] Investigating Miio Device at udp://192.168.1.44:54321 [4/21/2017, 9:18:22 AM] [homebridge-miio.XiaomiMiio] device discovered 52232795 [4/21/2017, 9:18:22 AM] [homebridge-miio.XiaomiMiio] Investigating Miio Device at udp://192.168.1.52:54321 [4/21/2017, 9:18:22 AM] [homebridge-miio.XiaomiMiio] device discovered 50671375 [4/21/2017, 9:18:22 AM] [homebridge-miio.XiaomiMiio] Investigating Miio Device at udp://192.168.1.46:54321 [4/21/2017, 9:18:22 AM] [homebridge-miio.XiaomiMiio] device discovered 55162641 [4/21/2017, 9:18:22 AM] [homebridge-miio.XiaomiMiio] Investigating Miio Device at udp://192.168.1.54:54321 [4/21/2017, 9:18:22 AM] [homebridge-miio.XiaomiMiio] device discovered 55164383 [4/21/2017, 9:18:22 AM] [homebridge-miio.XiaomiMiio] Investigating Miio Device at udp://192.168.1.48:54321 [4/21/2017, 9:18:23 AM] [homebridge-miio.XiaomiMiio] Unsupported, ignoring [4/21/2017, 9:18:23 AM] [homebridge-miio.XiaomiMiio] Unsupported, ignoring [4/21/2017, 9:18:25 AM] [homebridge-miio.XiaomiMiio] Miio Accessory is a switch plug. Adding to HomeKit [4/21/2017, 9:18:25 AM] [homebridge-miio.XiaomiMiio] miIO Plug 48618067 Configure Accessory [4/21/2017, 9:18:25 AM] [homebridge-miio.XiaomiMiio] Unsupported, ignoring events.js:160 throw er; // Unhandled 'error' event ^

Error: bind EADDRINUSE 0.0.0.0:9898 at Object.exports._errnoException (util.js:1018:11) at exports._exceptionWithHostPort (util.js:1041:20) at _handle.lookup (dgram.js:219:18) at _combinedTickCallback (internal/process/next_tick.js:83:11) at process._tickCallback (internal/process/next_tick.js:104:9)

Bluebie commented 7 years ago

Are you running on macOS? Sometimes macOS doesn't release the port, waiting a minute and trying again to run homebridge, or rebooting the computer, might help. If you still have the problem, I believe the new Aqara support in the underlying miio library could be conflicting with the homebridge-aqara plugin, so i could look in to that and see what I can do. If rebooting doesn't fix your issue, you could ask npm to install version 0.2.0 by uninstalling homebridge-miio and running npm install -g homebridge-miio@0.2.0

Please, let me know if the rebooting works.

fxdpz commented 7 years ago

Thx for quick response.

  1. I am running homebridge on raspberry, not on macOS.
  2. when i look the file AqaraPlatform.js at directory /usr/local/lib/node_modules/homebridge-aqara/lib, i found this: const dgram = require('dgram'); const inherits = require('util').inherits; const crypto = require('crypto'); const iv = Buffer.from([0x17, 0x99, 0x6d, 0x09, 0x3d, 0x28, 0xdd, 0xb3, 0xba, 0x69, 0x5a, 0x2e, 0x6f, 0x58, 0x56, 0x2e]); const serverSocket = dgram.createSocket('udp4'); const multicastAddress = '224.0.0.50'; const multicastPort = 4321; const serverPort = 9898; var AqaraAccessoryFactory;

so i think 0.2.1 conflicts with homebridge-aqara, same port 9898 is used. if i change 9898 to 9899 in aqara, homebridge will start with no error. but i got sluggish on getting sensor data from xiaomi gateway, and only one plugh is discoveryed(i have three xiaomi wifi plug, two is basic wifi plug and one is Xiaomi Smart Power Strip 69RMB(6 Plugs ) ZNCXB01ZM Made by Zumi). when i used 0.2.0, two basic wifi plug is discoveryed, when i used 0.2.1 with modified aqara server port ,only one(it seems to be ZNCXB01ZM) is discoveryed. now i revert aqara plugin server port and install 0.2.0, everything seems fine except Xiaomi Smart Power Strip is not discoveryed.

Bluebie commented 7 years ago

@aholstenson hmm!

fxdpz commented 7 years ago

PS: reboot didn't work.

aholstenson commented 7 years ago

@fxdpz This is due to me adding support for the Aqara (Mi Smart Home Gatway) in the miio-library. I think have a workaround that can be used in homebridge-aqara, in AqaraPlatform.js could you try changing the line const serverSocket = dgram.createSocket('udp4'); into:

const serverSocket = dgram.createSocket({
  type: 'udp4',
  reuseAddr: true
});

Does that help with running homebridge-aqara and 0.2.1 together?

@Bluebie A good idea might to be to check the type in the object that the discovery returns. In many cases it should be set to the type the device would become when it is connected to, and I'm going to improve it even more in the next version.

fxdpz commented 7 years ago

@aholstenson thx. i'll try later at night and get back to u. if miio library support mi smart home gateway, do i still need homebridge-aqara plugin?

Bluebie commented 7 years ago

miio library supports it, but homebridge-miio doesn't yet. I'm not sure if it will. It comes down to if I end up getting an aqara system at some point to test with, or if someone who has the gear writes the code and does a pull request. for now, stick with homebridge-aqara plugin

fxdpz commented 7 years ago

@aholstenson , after change serverSocket according to ur previous post, homebridge-aqara and homebridge-miio can running together without error. another question, is it possible that miio supoort this wifi plug(Xiaomi Smart Power Strip 69RMB(6 Plugs ) ZNCXB01ZM Made by Zumi)?

aholstenson commented 7 years ago

@fxdpz Nice to hear that solves the problem, I'll open a pull request for homebridge-aqara to see if the fix can be integrated directly in that project.

And yes, I added support for devices that identify themselves as zumi.powerstrip.v2 which I think is your device. Your model identifier is probably different or the token can not be automatically discovered. Please see https://github.com/aholstenson/miio/tree/master/docs/devices#finding-devices-on-your-network for how to find the device details that are needed and then feel free to open an issue in the miio repository.

astrojetson8 commented 7 years ago

great to see collaboration between @Bluebie and @aholstenson here's hoping @snOOrz can collaborate with you guys!

fxdpz commented 7 years ago

@aholstenson according to ur advice, I do a scan on my home network with command miio, here is the output: Discovering devices. Press Ctrl+C to stop.

Device ID: 52232795 Model: lumi.gateway.v3 Address: 192.168.1.52 (lumi-gateway-v3_miio52232795) Token:

Device ID: 50671375 Model: Unknown Address: 192.168.1.46 Token:

Device ID: 56290892 Model: yeelink.light.mono1 Address: 192.168.1.11 (yeelink-light-mono1_miio56290892) Token:

Device ID: 48618067 Model: zimi.powerstrip.v2 Address: 192.168.1.44 (zimi-powerstrip-v2_miio48618067) Token:

Device ID: 55164383 Model: chuangmi.plug.m1 Address: 192.168.1.48 (chuangmi-plug-m1_miio55164383) Token:

Device ID: 55162641 Model: chuangmi.plug.m1 Address: 192.168.1.54 (chuangmi-plug-m1_miio55162641) Token:

it seems that miio can find the zimi.powerstrip.v2, but I can not add it in home app on my phone. is it possible that homebridige-miio filtered?

===================================== update: After i reboot my pi, two plug and one powerstrip appears in the home app on my phone, but the name is reverted to some digit and i have to edit name and room. anyway, it works. thx.

aholstenson commented 7 years ago

I've opened a pull request in homebridge-aqara that should resolve this issue if it gets accepted. See snOOrz/homebridge-aqara#65.