Closed unparagoned closed 6 years ago
@Magrathea @codetheweb . I've made a simple mapper, items an rules so I can use your tuyapi. But I'm struggling with nodjs. Now and then I'm getting connection errors, usually a few in a row. I'm guessing this is to do with the fact I haven't properly killed previous session, or something. Do you mind having a glance at my code to see if anything stands out. https://github.com/unparagoned/njsTuya/blob/master/scripts/ohtuya.js
@unparagoned sorry about that. The current version of tuyapi attempts to continually keep a socket to the device open, which results in a lot of errors. Version 2.0 of tuyapi (coming soon) should fix this. There's nothing wrong with your code.
Changed to version 2.0 But still getting errors
(node:29942) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected end of JSON input
(node:29942) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Weird. Do you get any good results at all, or do calls always result in a error?
I forgot to put a option for debugging in v2.0. I'll try to add something in the next few days that will allow you to log returned values in more detail.
On Jan 13, 2018, at 15:38, unparagoned notifications@github.com wrote:
Changed to version 2.0 But still getting errors
(node:29942) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected end of JSON input
(node:29942) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
About 1/3 of the time there were no errors and worked fine. Mostly the toggle works but getting the state afterword is a problem. What I've done is just rework myscript so it doesn't ask for the state again and it seems to be working fine(edit: still get the errors now and then but much rarer). I just add some code around it and assume if a return result is true then it's changed state, rather than performing a second get call.
tuya.resolveIds().then(() => {
tuya.get().then(status => {
if (db) { console.log('Status: ' + status); }
newState = status;
if (args.includes("ON")) {
newState = true;
changeState = true;
}
if (args.includes("OFF")) {
newState = false;
changeState = true;
}
if (args.includes("TOGGLE")) {
newState = !status;
changeState = true;
}
if (changeState) {
tuya.set({ set: newState }).then(result => {
if (db) { console.log('Result of setting status to ' + newState + ': ' + result); }
if (result) {
console.log(bmap(!status));
} else {
console.log(bmap(status));
}
return;
});
} else {
console.log(bmap(status));
return;
}
});
});
https://github.com/unparagoned/njsTuya/blob/master/scripts/njstuya.js
Lock on rules and sleep seems to have fixed this error
Now and then there are connection errors. Might be due to to there only being one connection at at time. Maybe there are too many in a short period or maybe old connections aren't being closed.
`{ Error: read ECONNRESET