Giter VIP home page Giter VIP logo

Comments (7)

codetheweb avatar codetheweb commented on May 24, 2024

I just published an update that allows you to log some useful information to the console. Update tuyapi, then run your script with DEBUG=* node script.js.

Post the output here, and maybe we can figure out what's going on.

from tuyapi.

binary-person avatar binary-person commented on May 24, 2024

Same problem, I just used

process.on('unhandledRejection', (reason, p) => {
  console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
  process.exit(1);
});

in my main code to intentionally exit the program and used forever-monitor:

var forever = require('forever-monitor');
var child = new (forever.Monitor)('main.js');

child.on('watch:restart', function(info) {
    console.error('Restaring script because ' + info.file + ' changed');
});

child.on('restart', function() {
    console.error('Forever restarting script for ' + child.times + ' time');
});

child.on('exit:code', function(code) {
    console.error('Forever detected script exited with code ' + code);
});
child.start();

to keep it going.
Just an idea, hope it helps.
-- Simon

from tuyapi.

unparagoned avatar unparagoned commented on May 24, 2024

@codetheweb

[01:24:46] openhabian@debra:/etc/openhab2/scripts$ DEBUG=* node njstuya.js -ip 192.168.2.81 -id 012001865ccf7f598277 -key 00cfs888v58f12a TOGGLE
  TuyAPI Device(s):  +0ms
  TuyAPI [ { id: '01200***5ccf7f598277',
  TuyAPI     key: '00cfs***2v58f12a',
  TuyAPI     type: 'outlet',
  TuyAPI     uid: '',
  TuyAPI     port: 6668,
  TuyAPI     version: 3.1,
  TuyAPI     cipher:
  TuyAPI      { algorithm: [Object],
  TuyAPI        mode: [Object],
  TuyAPI        blockSize: 16,
  TuyAPI        _finish: false,
  TuyAPI        _input: null,
  TuyAPI        output: null,
  TuyAPI        _op: [Function],
  TuyAPI        _decrypt: false } } ] +2ms
  TuyAPI Received UDP message. +444ms
  TuyAPI Parsing this data to JSON:  000055aa00000000000000000000009e000000007b226970223a223139322e3136382e322e3831222c2267774964223a223031323030313836356363663766353938323737222c22616374697665223a322c226162696c697479223a302c226d6f6465223a302c22656e6372797074223a747275652c2270726f647563744b6579223a2271484c4e417a6d7252644139454d586c222c2276657273696f6e223a22332e31227dabd0b1910000aa55 +1ms
  TuyAPI Parsing this data to JSON:  000055aa00000000000000000000009e000000007b226970223a223139322e3136382e322e3831222c2267774964223a223031323030313836356363663766353938323737222c22616374697665223a322c226162696c697479223a302c226d6f6465223a302c22656e6372797074223a747275652c2270726f647563744b6579223a2271484c4e417a6d7252644139454d586c222c2276657273696f6e223a22332e31227dabd0b1910000aa55 +0ms
  TuyAPI Received UDP message. +2s
  TuyAPI Parsing this data to JSON:  000055aa00000000000000000000009f000000007b226970223a223139322e3136382e322e313435222c2267774964223a223031323030313836356363663766353937633162222c22616374697665223a322c226162696c697479223a302c226d6f6465223a302c22656e6372797074223a747275652c2270726f647563744b6579223a2271484c4e417a6d7252644139454d586c222c2276657273696f6e223a22332e31227dd494f9ea0000aa55 +0ms
  TuyAPI Payload:  +1ms
  TuyAPI { gwId: '01200***ccf7f598277', devId: '01200***5ccf7f598277' } +0ms
  TuyAPI Sending this data:  000055aa000000000000000a000000467b2267774964223a223031323030313836356363663766353938323737222c226465764964223a223031323030313836356363663766353938323737227d000000000000aa55 +1ms
  TuyAPI Received data back. +10ms
  TuyAPI Parsing this data to JSON:  000055aa000000000000000a0000003e000000007b226465764964223a223031323030313836356363663766353938323737222c22647073223a7b2231223a66616c73657d7df2b3e53c0000aa55 +0ms
  TuyAPI Payload:  +1ms
  TuyAPI { devId: '01200***ccf7f598277',
  TuyAPI   uid: '',
  TuyAPI   t: '1517189326',
  TuyAPI   dps: { '1': true } } +0ms
  TuyAPI Sending this data:  000055aa000000000000000700000087332e3137313962333433386237353063326436686b777a37724a553247356a45684365466935374a4a424c596131683444674668786f546172324d7a4d5438447130624869446a714e4c4565537138486e56344f79683756506f666644667244597851627947366c467648524c44646949764f494e53575a38676f6146553d000000000000aa55 +3ms
(node:7225) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Error communicating with device. Make sure nothing else is trying to control it or connected to it.
(node:7225) 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 tuyapi.

codetheweb avatar codetheweb commented on May 24, 2024

Weird. Everything looks fine. (Just a note: my setup works with ~95% reliability.) I'm sorry but there's not much I can help you with. Are you sure nothing else is trying to control it?

from tuyapi.

unparagoned avatar unparagoned commented on May 24, 2024

I'm pretty sure I don't have any other apps open and tried closing everything on the phone. But I'm playing about with virtually every home automation ecosystem, I've seen some bump into each other by mistake. What would the best way be to see everything talking to the switch? Can I simply fire up wireshark or would I need to set up some kind of proxy gateway to connect the switch through to monitor everything?

from tuyapi.

codetheweb avatar codetheweb commented on May 24, 2024

If every possible device that could be controlling it is connected via WiFi, it should be possible to monitor connections to it with Wireshark (although I'm not 100% sure on this).

I'm currently in the process of adding a retry function if net.connect() returns with a ECONNRESET error. Hopefully this will reduce errors for you.

from tuyapi.

unparagoned avatar unparagoned commented on May 24, 2024

I've made a few changes so not sure what has fixed it. I've got locking and some small time delays to prevent the script being run to close to a previous run. Errors are infrequent now, and when I come into contact with one I just rerun the command.

I'm closing this since I'm having difficulty even creating the error anymore.

from tuyapi.

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.