Comments (6)
@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
from njstuya.
@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.
from njstuya.
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.
from njstuya.
from njstuya.
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
from njstuya.
Lock on rules and sleep seems to have fixed this error
from njstuya.
Related Issues (20)
- get/set command format issue with openhab
- is there a way to set set multiple dps options in one command? HOT 1
- Multi-outlet Devices HOT 4
- Error in openHAB HOT 5
- Status HOT 6
- Trying to understand local and cloud mode HOT 5
- Does this also work with the Woox products? HOT 5
- Cannot read schema from device. HOT 1
- Problem with Emylo SS-8839-03 and njstuya local
- "Error: find() timed out." when running "sudo node node_modules/njstuya" HOT 1
- Problem with connection to device after firmware upgrade HOT 5
- Tuya Curtain switch HOT 1
- Plug Compatibility Question - HOT 13
- Gusund Wall Switch does not respond to njstuya commands HOT 1
- debug error on run HOT 1
- Can't read the schema HOT 2
- Please add device - wattmeter. HOT 1
- Commands not send anymore HOT 2
- After upgrading my pi and then rebooting ... HOT 1
- Unable to authenticate after upgrade HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from njstuya.