codetheweb / tuyapi

🌧 An easy-to-use API for devices that use Tuya's cloud services. Documentation: https://codetheweb.github.io/tuyapi.
MIT License
2.05k stars 337 forks source link

It works but the process don't end #13

Closed ybabel closed 6 years ago

ybabel commented 6 years ago

Hello. The script works fine, I can switch my plug on/off but, the node process doesn't quit and I get an infinite loop :

Status: true
Result of setting status to false: true
New status: false
{ Error: read ECONNRESET
    at exports._errnoException (util.js:1020:11)
    at TCP.onread (net.js:568:26) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }
{ Error: read ECONNRESET
    at exports._errnoException (util.js:1020:11)
    at TCP.onread (net.js:568:26) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }
[again and again]

running on ubuntu 17.10 node v6.11.4 and rasbpian node v6.12.2. Any clue ?

Notice I also get the same problem with only a getStatus :

    const TuyaDevice = require('tuyapi');

    var tuya = new TuyaDevice({
      type: 'outlet',
      ip: '192.168.0.18',
      id: 'xxxx',
      key: 'xxxx'
    });
    tuya.getStatus(function(error, status) {
      if (error) { return console.log(error); }
      console.log('Status: ' + status);
    });
codetheweb commented 6 years ago

Yes, that's currently the expected behavior. To end the script, call tuya.destroy(). It currently attempts to keep the socket connected indefinitely. However, I realize that may not be the best solution to fixing Tuya's crummy API. I'm still thinking about alternative solutions. If you have any ideas, I'm open to hearing them.