codetheweb / tuyapi

🌧 An easy-to-use API for devices that use Tuya's cloud services. Documentation: https://codetheweb.github.io/tuyapi.
MIT License
2.04k stars 332 forks source link

ECONNREFUSED Error when attempting to connect to devices #342

Closed MTXgames closed 3 years ago

MTXgames commented 4 years ago

Hello! This is my first time posting about a support issue, and I'm still heavily in the learning process here with home automation, so bear with me. Currently, I've been working on getting my tuya wifi bulbs from feit electric to connect to my openhab system. I feel like I'm VERY close to getting it all good to go, but this is my last hurdle I'm not sure how to get working properly. When I start up tuya-mqtt.js, things seem relatively fine, however when i try to switch the lightbulb on/off using the basicUI from the items and sitemap i configured, this is the debug error I get from tuya-mqtt.js:

TuyAPI:mqtt MQTT-Server nicht verbunden. +0ms TuyAPI:mqtt Verbindung mit MQTT-Server hergestellt +12ms TuyAPI:mqtt receive settings {"topic":"tuya/lightbulb/XXX/XXX/XXX/command","action":"command","message":"OFF","options":{"id":"XXX","key":"XXX","ip":"XXX","type":"lightbulb"}} +14m TuyAPI:device Search device in network +0ms TuyAPI IP and ID are already both resolved. +0ms TuyAPI:device Device found in network +14ms TuyAPI Connecting to XXX... +10ms TuyAPI Error event from socket. XXX { Error: connect ECONNREFUSED XXX:6668 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14) errno: 'ECONNREFUSED', code: 'ECONNREFUSED', syscall: 'connect', address: 'XXX', port: 6668 } +9ms TuyAPI:device:error Error: Error from socket TuyAPI:device:error at Socket.client.on.err (/etc/openhab2/scripts/tuya-mqtt/node_modules/tuyapi/index.js:365:30) TuyAPI:device:error at Socket.emit (events.js:198:13) TuyAPI:device:error at emitErrorNT (internal/streams/destroy.js:91:8) TuyAPI:device:error at emitErrorAndCloseNT (internal/streams/destroy.js:59:3) TuyAPI:device:error at process._tickCallback (internal/process/next_tick.js:63:19) +0ms TuyAPI:mqtt:error { error: TuyAPI:mqtt:error Error: Error from socket TuyAPI:mqtt:error at Socket.client.on.err (/etc/openhab2/scripts/tuya-mqtt/node_modules/tuyapi/index.js:365:30) TuyAPI:mqtt:error at Socket.emit (events.js:198:13) TuyAPI:mqtt:error at emitErrorNT (internal/streams/destroy.js:91:8) TuyAPI:mqtt:error at emitErrorAndCloseNT (internal/streams/destroy.js:59:3) TuyAPI:mqtt:error at process._tickCallback (internal/process/next_tick.js:63:19), TuyAPI:mqtt:error device: TuyAPI:mqtt:error TuyaDevice { TuyAPI:mqtt:error type: 'lightbulb', TuyAPI:mqtt:error options: TuyAPI:mqtt:error { id: 'XXX', TuyAPI:mqtt:error key: 'XXX', TuyAPI:mqtt:error ip: 'XXX', TuyAPI:mqtt:error type: 'lightbulb' } } } +0ms TuyAPI Socket closed: XXX +55ms TuyAPI:device Disconnected from device. lightbulb (XXX, XXX, XXX) +68ms TuyAPI:device delete Device lightbulb (XXX, XXX, XXX) +1ms

From what this looks like, I think the bulb is refusing a connection with the tuya-mqtt for some reason? Is there a step I missed or did i incorrectly program something? all my bulbs are no longer configured to any tuya-related app. I had to do tuya-cli link along with the tuya developer instructions to get the localkeys. They seem to be connected to my wifi fine i believe since they're not blinking... I did have to specifically run that on a seperate computer from the machine OpenHAB is currently running on, as it's important to note my system has ethernet connection only. Since that was an issue getting localkeys, could that be an issue here as well?

If there's any other details you need I'm happy to provide them! I'm still brand new at all of this, and new to linux as well, so there's a lot i'm trying to learn on the fly, and I wouldn't be surprised if this was caused by some mistake down the line. I think I Xed out all the private info, but if i missed something let me know as well. Regardless, thank you for your patience!

Current Specs that is running the processes: Linux Mint 20 v.4.6.6 intel core 2 duo CPU E6400 @ 2.13Ghz x 2 3.8GB RAM 1TB HDD intel corp. 82q963/q965 integrated graphics controller

codetheweb commented 4 years ago

Took a quick look at the mqtt script and it looks like it's using quite an old version of TuyAPI. I would recomend changing the version of TuyAPI in package.json to 5.3.1 and see if that fixes your issue. If you continue to have problems and think that it might be the mqtt script's fault and not TuyAPI, please open an issue over there.

MTXgames commented 4 years ago

Yeaah, I changed the version but unfortunately I still have the same issue. At least this can narrow it down a little bit! Thank you!

codetheweb commented 3 years ago

Ok, if you want any further help debugging let me know.

tsightler commented 3 years ago

Trying to update tuya-mqtt after all this time since it still seems to have some users out there. I've bumped to the latest TuyAPI, but I still see the ECONNREFUSED seemingly randomly during startup. It happens on different devices each time and I can't really figure it out as usually the next attempt works. I'll probably just put something in the code to try again in the case that the connection fails.