rebtor / nl.rebtor.tuya

TuyAPI implementation for homey
MIT License
7 stars 8 forks source link

Error: Error: Error from socket: connect ECONNREFUSED 127.0.0.1:6668 #35

Closed torarnv closed 1 year ago

torarnv commented 1 year ago

Hi,

I'm trying to run this app locally for my 2023 Homey Pro, so I can fix some issues with my bulb.

But after starting the app with homey app run, adding a bulb, and then trying to turn it on/off, I get:

2023-08-05T11:27:19.501Z [log] [Tuyadriver] Tuyadriver is running...
Device name:  Filament LED: Pære 1/6 has been inited

Error:  Error: Error from socket: connect ECONNREFUSED 127.0.0.1:6668
    at Socket.<anonymous> (/app/node_modules/tuyapi/index.js:627:26)
    at Socket.emit (node:events:513:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

I've tried setting an explicit IP for the bulb in the configuration, but it still tries to connect to 127.0.0.1. Any idea what's going on?

I'm running the app on a Mac, via Colima instead of Docker, but the image should still be able to connect to IPs in my local network.

torarnv commented 1 year ago

Setting an explicit IP only seems to take effect after restarting the app.

It now can connect to the bulb and can investigate the data errors.

Not sure why it wasn't able to auto-detect the IP?

torarnv commented 1 year ago

Tried running with docker app run -r to run it on the Homey instead of locally with Docker, in case the issue was that the Docker setup was preventing the app from enumerating the IPs of devices via UDP multicast or similar.

But still getting:

Error:  Error: Error from socket: connect ECONNREFUSED ::1:6668
    at Socket.<anonymous> (/app/node_modules/tuyapi/index.js:627:26)
    at Socket.emit (node:events:513:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
torarnv commented 1 year ago

The fundamental issue has been fixed by https://github.com/athombv/node-homey/pull/353

Running the app locally with host networking allows UDP multicast. The same can be done by homey app run -r for running directly on the device, but of course that has a slower edit/run cycle.

There's still an issue where the app will try to connect to 127.0.0.1 or ::1 around five times before TuyaAPI starts the process of looking for the IP: TuyAPI Finding missing IP or ID <ID>. Not sure why that is.

torarnv commented 1 year ago

The initial delay on startup or when adding a device is fixed by https://github.com/torarnv/nl.rebtor.tuya/commit/d9b04d789d35164a6a016ad9854b8592c040e594

torarnv commented 1 year ago

This should be fixed now by https://github.com/athombv/node-homey/pull/353 and https://github.com/torarnv/nl.rebtor.tuya/commit/d9b04d789d35164a6a016ad9854b8592c040e594