Giter Site home page Giter Site logo

Connection Error about njstuya HOT 6 CLOSED

unparagoned avatar unparagoned commented on September 16, 2024
Connection Error

from njstuya.

Comments (6)

unparagoned avatar unparagoned commented on September 16, 2024

@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.

codetheweb avatar codetheweb commented on September 16, 2024

@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.

unparagoned avatar unparagoned commented on September 16, 2024

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.

codetheweb avatar codetheweb commented on September 16, 2024

from njstuya.

unparagoned avatar unparagoned commented on September 16, 2024

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.

unparagoned avatar unparagoned commented on September 16, 2024

Lock on rules and sleep seems to have fixed this error

from njstuya.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.