AMoo-Miki / homebridge-tuya-lan

Homebridge plugin for IoT devices that use Tuya Smart's platform
MIT License
202 stars 51 forks source link

Problem with TuyaAccessory #3

Closed Fabinewchurch closed 5 years ago

Fabinewchurch commented 5 years ago

Hi, I have a general problem using the homebridge-tuya-lan plugin. I installed the plugin and edited the config.jsion (using a RGBTWLight) but homebridge always gives me this the following error:

[TuyaAccessory] Discovery error: Error: bind EADDRINUSE 0.0.0.0:6666 at Object._errnoException (util.js:1022:11) at _exceptionWithHostPort (util.js:1044:20) at _handle.lookup (dgram.js:266:18) at _combinedTickCallback (internal/process/next_tick.js:141:11) at process._tickCallback (internal/process/next_tick.js:180:9) at Function.Module.runMain (module.js:695:11) at startup (bootstrap_node.js:188:16) at bootstrap_node.js:609:3 [TuyaAccessory] Discovery stopped. Restarting... /opt/node/lib/node_modules/homebridge-tuya-lan/lib/TuyaAccessory.js:315 server.start(); ^

TypeError: server.start is not a function at process.nextTick (/opt/node/lib/node_modules/homebridge-tuya-lan/lib/TuyaAccessory.js:315:24) at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickCallback (internal/process/next_tick.js:180:9) at Function.Module.runMain (module.js:695:11) at startup (bootstrap_node.js:188:16) at bootstrap_node.js:609:3

AMoo-Miki commented 5 years ago

Hi,

This error means something is using your port 6666. To know which process is using it, run this command: sudo netstat -anp | grep :6666. If it doesn't return anything, that would mean something is using the port temporarily and not all the time. While there is no workaround to use a different port, I will add a mechanism to retry until the port is free.

AMoo-Miki commented 5 years ago

I just published v1.1.4 which has the ability to retry binding to 6666 when it is found to be in use. To update the plugin, run npm i -g homebridge-tuya-lan.

Please let me know if that helps. If the other program doesn't let go the port, let me know who that is and I will get in touch with its author to find a solution.

Fabinewchurch commented 5 years ago

Hi, thanks for the quick answer. I updated the plugin, now the error is as follows:

[TuyaAccessory] Discovery error: Port 6666 is in use. Will retry in 15 seconds. [TuyaAccessory] Discovery stopped.

...

`[TuyaAccessory] Discovery restarting... [TuyaAccessory] Discovery started. /usr/lib/node_modules/homebridge-tuya-lan/index.js:64 this.log.debug('Discovered %s (%s)', devices[config.id].name, config.id); ^

TypeError: Cannot read property 'name' of undefined at EventEmitter.TuyaAccessory.discover.on.config (/usr/lib/node_modules/homebridge-tuya-lan/index.js:64:73) at emitOne (events.js:116:13) at EventEmitter.emit (events.js:211:7) at Socket.server.on.msg (/usr/lib/node_modules/homebridge-tuya-lan/lib/TuyaAccessory.js:340:24) at emitTwo (events.js:126:13) at Socket.emit (events.js:214:7) at UDP.onMessage [as onmessage] (dgram.js:659:8)

I also ran:

sudo netstat -anp | grep :6666

during normal use this gives back nothing, during the 15s before retry it gives the following:

udp 0 0 0.0.0.0:6666 0.0.0.0:* 5116/homebridge

AMoo-Miki commented 5 years ago

This is great; we were able to bypass the other process that used UDP discovery.

The error you see now is due to my failure to validate any discovered devices that have not been configured to use this plugin; I apologize. This has been fixed in v1.1.5 of the plugin; to update the plugin, run npm i -g homebridge-tuya-lan.

Fabinewchurch commented 5 years ago

Hi, thanks for the great work! I updated the plugin. Now there is no error anymore,

But how do I configure a new device?

What I get back now is:

[TuyaLan] Discovered a device that has not been configured yet (the devices id) [TuyaLan] Failed to discover name in time but will keep looking.

AMoo-Miki commented 5 years ago

Can you paste what you used in the config for Homebridge? Also, did you go through the step 4 of the Setup Instructions to get the id and key combo?

In your config parameters, check for unwanted spaces around the ids and keys. It appears that there are devices that the plugin hears from during discovery but those have not been defined in your config. Additionally, the device that has been configured, doesn't appear to be one that got discovered on your network; this could happen if the an id was mistyped.

Good luck.

whyidie commented 5 years ago

Getting a similar error in terms of the port being used :

[2019-1-9 16:38:37] [TuyaLan] Starting discovery... Wed, 09 Jan 2019 23:38:37 GMT EventedHTTPServer Server listening on port 51826 [2019-1-9 16:38:37] Homebridge is running on port 51826. [TuyaAccessory] Discovery error: Port 6666 is in use. Will retry in 15 seconds. [TuyaAccessory] Discovery stopped. [TuyaAccessory] Discovery restarting... [TuyaAccessory] Discovery error: Port 6666 is in use. Will retry in 15 seconds. [TuyaAccessory] Discovery stopped. [TuyaAccessory] Discovery restarting... [TuyaAccessory] Discovery error: Port 6666 is in use. Will retry in 15 seconds. [TuyaAccessory] Discovery stopped. [TuyaAccessory] Discovery restarting... [TuyaAccessory] Discovery error: Port 6666 is in use. Will retry in 15 seconds. [TuyaAccessory] Discovery stopped. [2019-1-9 16:39:37] [TuyaLan] Failed to discover bulb 1 in time but will keep looking. [2019-1-9 16:39:37] [TuyaLan] Failed to discover bulb 2 in time but will keep looking. [2019-1-9 16:39:37] [TuyaLan] Failed to discover bulb 3 in time but will keep looking. [TuyaAccessory] Discovery restarting... [TuyaAccessory] Discovery error: Port 6666 is in use. Will retry in 15 seconds. [TuyaAccessory] Discovery stopped. [TuyaAccessory] Discovery restarting... [TuyaAccessory] Discovery error: Port 6666 is in use. Will retry in 15 seconds. [TuyaAccessory] Discovery stopped. [TuyaAccessory] Discovery restarting... [TuyaAccessory] Discovery error: Port 6666 is in use. Will retry in 15 seconds. [TuyaAccessory] Discovery stopped. [TuyaAccessory] Discovery restarting... [TuyaAccessory] Discovery error: Port 6666 is in use. Will retry in 15 seconds. [TuyaAccessory] Discovery stopped. [TuyaAccessory] Discovery restarting... [TuyaAccessory] Discovery error: Port 6666 is in use. Will retry in 15 seconds. [TuyaAccessory] Discovery stopped.

whyidie commented 5 years ago

$ netstat -a | grep :6666 UDP 0.0.0.0:6666 :

whyidie commented 5 years ago

Turned out to be Epic Games launcher. Killed it and now I'm on to a new error. Won't post it here as the root problem may be different than ports being blocked :

$ netstat -a -n -o | grep 6666

UDP 0.0.0.0:6666 : 11472

ps -W | grep 11472 11472 0 0 11472 ? 0 16:32:16 > C:\ProgramFiles(x86)\EpicGames\Launcher\Portal\Binaries\Win64\EpicGamesLauncher.exe

AMoo-Miki commented 5 years ago

I am glad you found what was using the port. When the plugin finds that it is unable to open the port, it tries periodically, hoping that it is just another plugin using the port temporarily. Of course that becomes a problem when that other process doesn't release the port.