bewee / tuya-adapter

GNU General Public License v3.0
9 stars 8 forks source link

Devices disconnect and never come back #38

Open freaktechnik opened 2 years ago

freaktechnik commented 2 years ago

When a device gets disconnected the only way to get it back seems to be to restart the adapter? Not even pairing manages to get them connected again.

bewee commented 2 years ago

That's weird... The adapter should regularly try to reconnect disconnected devices - I cannot reproduce this problem. Which type of device do you use? Do the logs (with log level set to debug) tell something interesting?

PS: I did notice some lag from time to time lately, but thought this was just a problem with tuya. But maybe this is related to your problem?

freaktechnik commented 2 years ago

It does try to reconnect, however it will error with

Internal tuyapi error Error: Error from socket
2022-01-31 09:39:08.236 ERROR  : tuya-adapter:     at Socket.<anonymous> (/home/node/.webthings/addons/tuya-adapter/node_modules/tuyapi/index.js:399:30)
2022-01-31 09:39:08.236 ERROR  : tuya-adapter:     at Socket.emit (events.js:314:20)
2022-01-31 09:39:08.236 ERROR  : tuya-adapter:     at emitErrorNT (internal/streams/destroy.js:92:8)
2022-01-31 09:39:08.236 ERROR  : tuya-adapter:     at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
2022-01-31 09:39:08.236 ERROR  : tuya-adapter:     at processTicksAndRejections (internal/process/task_queues.js:84:21)

(though interestingly it also errored once after restarting the adapter in my testing)

bewee commented 2 years ago

Hm, maybe it's really a tuya or tuyapi related problem?

I found this commit in tuyapi which passes through the full socket error. Will upgrade this addon to use the latest tuyapi version. Maybe this already fixes your problem, or at least gives us some more context

bewee commented 2 years ago

Ok, so I may have figured it out. Could you checkout https://github.com/bewee/tuya-adapter/pull/40 and tell me whether this fix works for you?

freaktechnik commented 2 years ago

I installed the adapter from the PR and still seeing a bunch of

2022-02-03 09:05:18.724 ERROR  : tuya-adapter: tuya-bf4a38b44120d33349ich2 Internal tuyapi error Error: Error from socket: read ECONNRESET
2022-02-03 09:05:18.724 ERROR  : tuya-adapter:     at Socket.<anonymous> (/home/node/.webthings/addons/tuya-adapter/node_modules/tuyapi/index.js:520:30)
2022-02-03 09:05:18.724 ERROR  : tuya-adapter:     at Socket.emit (events.js:314:20)
2022-02-03 09:05:18.724 ERROR  : tuya-adapter:     at emitErrorNT (internal/streams/destroy.js:92:8)
2022-02-03 09:05:18.724 ERROR  : tuya-adapter:     at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
2022-02-03 09:05:18.724 ERROR  : tuya-adapter:     at processTicksAndRejections (internal/process/task_queues.js:84:21)

(about once every minute it seems)

freaktechnik commented 2 years ago

By the way, interestingly changing properties works most times, even when the device is disconnected and will make it show as connected briefly.

bewee commented 2 years ago

I installed the adapter from the PR and still seeing a bunch of

2022-02-03 09:05:18.724 ERROR  : tuya-adapter: tuya-bf4a38b44120d33349ich2 Internal tuyapi error Error: Error from socket: read ECONNRESET
2022-02-03 09:05:18.724 ERROR  : tuya-adapter:     at Socket.<anonymous> (/home/node/.webthings/addons/tuya-adapter/node_modules/tuyapi/index.js:520:30)
2022-02-03 09:05:18.724 ERROR  : tuya-adapter:     at Socket.emit (events.js:314:20)
2022-02-03 09:05:18.724 ERROR  : tuya-adapter:     at emitErrorNT (internal/streams/destroy.js:92:8)
2022-02-03 09:05:18.724 ERROR  : tuya-adapter:     at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
2022-02-03 09:05:18.724 ERROR  : tuya-adapter:     at processTicksAndRejections (internal/process/task_queues.js:84:21)

(about once every minute it seems)

I presume that is intended behaviour: The addon tries to reconnect, which errors since the device is not yet connected to the network again. Not seeing any errors would be worse since then the addon wouldn't even try :D

What connection timeout have you set in your addon config? This value indirectly determines the interval in which reconnects are attempted. It may take up to about twice this duration until the device will be shown as connected again. Have you waited this long? With the fix, when I turned off my light, it reconnected reliably about a minute after I turned it back on

freaktechnik commented 2 years ago

I don't quite understand why the device would disconnect from the network every minute though?

bewee commented 2 years ago

Oh, you mean this happens without you doing something (like turning off the device)

Yeah, this definitely shouldn't happen. Does the device work flawlessly with the original app?

bewee commented 2 years ago

ECONNRESET really points to some sort of networking problem I guess?

freaktechnik commented 2 years ago

Worked just fine with the app, though the app replaces the connection the adapter has to the device, so I've uninstalled it for now. To me it seems more like somehow there are sockets being created that aren't getting cleaned up, or the adapter is querying something on the device that the device doesn't like and disconnects. From the properties I can see it's correctly handling the device though.

bewee commented 2 years ago

Sounds reasonable, however I have no clue where this could originate from and it's hard to debug without being able to reproduce the problem, so I think there is little I can do for you right now. But I'd be happy to help with a PR if you can identify the cause :)

bewee commented 2 years ago

Will merge #40 as it at least fixes the (seemingly different) issue on my end

freaktechnik commented 2 years ago

I might also have encountered the issue #40 fixes, but it's just compounded with something else :/