ewelink-api
ewelink-api copied to clipboard
Slow api, ETIMEDOUT, ECONRESET, ECONNREFUSED
const ewelink = require('ewelink-api');
(async () => {
let start = Date.now();
const connection = new ewelink({
email: '...',
password: '...',
region: 'eu',
});
console.log('connection', (Date.now() - start) / 1000);
try {
/* get all devices */
start = Date.now();
const devices = await connection.getDevices();
console.log('devices', (Date.now() - start) / 1000);
/* get specific devide info */
start = Date.now();
const device = await connection.getDevice('...');
console.log('device', (Date.now() - start) / 1000);
console.log('end');
} catch(e){
console.log('exception', (Date.now() - start) / 1000);
console.log(e);
}
})();
Above code results in wide range of connection errors:
\...\_ewelink-test>node test.js
connection 0
\...\_ewelink-test\node_modules\node-fetch\lib\index.js:1505
reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
^
FetchError: request to https://eu-api.coolkit.cc:8080/api/user/login failed, reason: connect ECONNREFUSED 52.57.118.192:8080
at ClientRequest.<anonymous> (\...\_ewelink-test\node_modules\node-fetch\lib\index.js:1505:11)
at ClientRequest.emit (node:events:527:28)
at TLSSocket.socketErrorListener (node:_http_client:454:9)
at TLSSocket.emit (node:events:527: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) {
type: 'system',
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED'
}
\...\_ewelink-test>node test.js
connection 1
\...\_ewelink-test\node_modules\node-fetch\lib\index.js:1505
reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
^
FetchError: request to https://eu-api.coolkit.cc:8080/api/user/device?lang=en&appid=...&ts=1677441318&version=8&getTags=1 failed, reason: read ECONNRESET
at ClientRequest.<anonymous> (\...\_ewelink-test\node_modules\node-fetch\lib\index.js:1505:11)
at ClientRequest.emit (node:events:527:28)
at TLSSocket.socketErrorListener (node:_http_client:454:9)
at TLSSocket.emit (node:events:527: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) {
type: 'system',
errno: 'ECONNRESET',
code: 'ECONNRESET'
}
\...\_ewelink-test>node test.js
connection 0
exception 17.593
FetchError: request to https://eu-api.coolkit.cc:8080/api/user/login failed, reason: connect ECONNREFUSED 52.57.118.192:8080
at ClientRequest.<anonymous> (\...\_ewelink-test\node_modules\node-fetch\lib\index.js:1505:11)
at ClientRequest.emit (node:events:527:28)
at TLSSocket.socketErrorListener (node:_http_client:454:9)
at TLSSocket.emit (node:events:527: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) {
type: 'system',
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED'
}
\...\_ewelink-test>node test.js
connection 0
exception 68.915
FetchError: request to https://eu-api.coolkit.cc:8080/api/user/login failed, reason: read ECONNRESET
at ClientRequest.<anonymous> (\...\_ewelink-test\node_modules\node-fetch\lib\index.js:1505:11)
at ClientRequest.emit (node:events:527:28)
at TLSSocket.socketErrorListener (node:_http_client:454:9)
at TLSSocket.emit (node:events:527: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) {
type: 'system',
errno: 'ECONNRESET',
code: 'ECONNRESET'
}
\...\_ewelink-test>node test.js
connection 0
exception 168.683
FetchError: request to https://eu-api.coolkit.cc:8080/api/user/login failed, reason: read ECONNRESET
at ClientRequest.<anonymous> (\...\_ewelink-test\node_modules\node-fetch\lib\index.js:1505:11)
at ClientRequest.emit (node:events:527:28)
at TLSSocket.socketErrorListener (node:_http_client:454:9)
at TLSSocket.emit (node:events:527: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) {
type: 'system',
errno: 'ECONNRESET',
code: 'ECONNRESET'
}
Pinging the IP of the endpoint works.
Running the same code on linux server does work most of the time but the times of execution are unacceptable:
# node test.js
connection 0
devices 28.744
device 11.362
end
# node test.js
connection 0
devices 88.173
device 13.592
end
# node test.js
connection 0.001
exception 172.009
FetchError: request to https://eu-api.coolkit.cc:8080/api/user/device?lang=en&appid=...&ts=1677442551&version=8&getTags=1 failed, reason: connect ETIMEDOUT 52.57.118.192:8080
at ClientRequest.<anonymous> (/root/_/ewelink-test/node_modules/node-fetch/lib/index.js:1505:11)
at ClientRequest.emit (node:events:378:20)
at TLSSocket.socketErrorListener (node:_http_client:462:9)
at TLSSocket.emit (node:events:378:20)
at emitErrorNT (node:internal/streams/destroy:188:8)
at emitErrorCloseNT (node:internal/streams/destroy:153:3)
at processTicksAndRejections (node:internal/process/task_queues:81:21) {
type: 'system',
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT'
}
It was working good before, it started to malfunction about 2 days ago so ~ 2023-02-24
Same here. Stopped working 1-2 days ago. If anyone has a clue how to fix it it would be great. In the meanwhile you can consider switching to webhooks. A little bit cumbersome to setup with ewelink web (scenes) but works until there is a bugfix, unless you need to read out states.
Same problem!
Same issue (not a surprise ... the same enpoint). What is a kind of surprise - the websocket callbacks work still well.
Same Problem, where I can report this issued=?
Same problem here :(
Seems like https://eu-api.coolkit.cc:8080 is not responding (or very inconsistently).
The 'us' server is responding, but cannot be used with EU ewelink accounts...
There are talks on the eWeLink Telegram group about how their server may have been overloaded, maybe an accidental DDoS through someone's bad code, who knows. I can get a login every now and then, but then as soon as you try do anything it seems the authentication is now broken as well. So I keep getting a { error: 406, msg: 'Authentication failed' } response using this package, the Postman response below shows it's not accepting the Bearer token anymore.
I also believe the accidental DoS is a likely explanation. That answers why the websocket interface still works well ... without any delay. Btw the status of the "main" control API is not consistent, a while ago it worked well. At this moment it still works but slow (~20 sec delay).
Interestingly the mobile app and web portal are triggering my relays instantly. Apparently the API this package uses is not officially supported by eWeLink, so I don't think we can count on a quick resolution from them here. Busy fishing around the web portal to see if there's anything I can grab onto there.
FYI https://coolkit-technologies.github.io/eWeLink-API/#/en/PlatformOverview
Has anyone tested branch 4.0.0 already? IDK if it's worth spending time testing it
Has anyone tested branch 4.0.0 already? IDK if it's worth spending time testing it
It's not an issue of this library, its a problem on eweLink's server, so you can't fix it by changing to any version of this library here.
Hopefully it will be back soon. The https://eu-api.coolkit.cc:8080 response went from 503 to the OpenResty default page already, so they are working on it.
Has anyone tested branch 4.0.0 already? IDK if it's worth spending time testing it
It's not an issue of this library, its a problem on eweLink's server, so you can't fix it by changing to any version of this library here.
Hopefully it will be back soon. The https://eu-api.coolkit.cc:8080 response went from 503 to the OpenResty default page already, so they are working on it.
Just noticed that this branch changes API addresses and uses V2, maybe it uses different routes on load balancers and works, just didn't have time to test it
I just testing th api now, and its works fine without delay, seems solved now!!!. 3 days to solved this, is too much.... There are other way to control ewelink devices? Sonoff zero in lan does not work correctly in certain situations with 2 canal devices.. there is some documentation to work with the devices on lan? without this api?