codetheweb / homebridge-tuya-outlet

A plugin for Homebridge for Tuya-based outlets
15 stars 11 forks source link

Error When Tapping Accessory In Home #19

Closed lswee closed 6 years ago

lswee commented 6 years ago

Everything is running, but when I tap it in Home I get the following:

[6/7/2018, 8:44:29 PM] Homebridge is running on port 51826. /usr/local/lib/node_modules/homebridge-tuya-outlet/node_modules/tuyapi/index.js:171 const thisData = Buffer.from(JSON.stringify(requests[currentDevice.type].status.command)); ^

TypeError: this is not a typed array. at Function.from (native) at TuyaDevice.resolveIds.TuyaDevice.get.Promise [as get] (/usr/local/lib/node_modules/homebridge-tuya-outlet/node_modules/tuyapi/index.js:171:27) at TuyaOutlet._setOn.TuyaOutlet._get.callback.tuya.get.then [as _get] (/usr/local/lib/node_modules/homebridge-tuya-outlet/index.js:39:13) at emitThree (events.js:97:13) at emit (events.js:175:7) at Characteristic.getValue (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Characteristic.js:163:10) at Bridge. (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:760:20) at Array.forEach (native) at Bridge.Accessory._handleGetCharacteristics (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:724:8) at emitMany (events.js:108:13)

I'm also unsure as to which IP address to use, as I can see a local one if I search for devices using my router then match up the MAC. But within Tuya there is a different external IP address.

Any help would be greatly appreciated. I feel so close to getting it working!

codetheweb commented 6 years ago

Weird error. Does it work if you use tuyapi directly? You should be passing in the local IP of the device, not your network's public IP.

lswee commented 6 years ago

I mean to say that according to my router the plug is at 192.168.0.41

Within the Device Info in the TuyaSmart app it has an IP beginning with 82.

Any idea why that would be?

How can I test it directly?

codetheweb commented 6 years ago

Yes, the Tuya app only lists the external IP - not the internal/local IP that you need. 192.168.0.41 is the IP that you need to use.

Test it directly by

  1. Install tuyapi globally: npm i tuyapi -g
  2. Create a test script:
    
    const TuyaDevice = require('tuyapi');

let tuya = new TuyaDevice({ id: 'xxxxxxxxxxxxxxxxxxxx', key: 'xxxxxxxxxxxxxxxx', ip: '192.168.0.41'});

tuya.get().then(status => { console.log('Status: ' + status);

tuya.set({set: !status}).then(result => { console.log('Result of setting status to ' + !status + ': ' + result);

tuya.get().then(status => {
  console.log('New status: ' + status);
  return;
});

}); });



If it doesn't work, re-run with `DEBUG=* node script.js` and post the results.
lswee commented 6 years ago

Thanks, I'll use that one then.

Perhaps I need to update node/npm?

pi@raspberrypi:~ $ node script.js /home/pi/script.js:3 let tuya = new TuyaDevice({ ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:413:25) at Object.Module._extensions..js (module.js:452:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Function.Module.runMain (module.js:475:10) at startup (node.js:117:18) at node.js:951:3

pi@raspberrypi:~ $ node -v v4.0.0

UPDATE: Yeah, it's an issue with my Pi and npm, investigating...

pi@raspberrypi:~ $ npm -v /usr/local/lib/node_modules/npm/node_modules/npmlog/log.js:57 log.progressEnabled = log.gauge.isEnabled() ^

TypeError: log.gauge.isEnabled is not a function at Object. (/usr/local/lib/node_modules/npm/node_modules/npmlog/log.js:57:33) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3) at Module.require (internal/modules/cjs/loader.js:650:17) at require (internal/modules/cjs/helpers.js:20:18) at /usr/local/lib/node_modules/npm/bin/npm-cli.js:22:13 at Object. (/usr/local/lib/node_modules/npm/bin/npm-cli.js:145:3)

codetheweb commented 6 years ago

Yeah, your Node version is way out of date 😅. Upgrade to at least v8.0.0.

lswee commented 6 years ago

How silly! Well that script is working now, probably need to re-install homebridge properly...

codetheweb commented 6 years ago

👍

lswee commented 6 years ago

All working. Three devices without a problem.

I started from scratch and found a version of node and npm which worked: curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - sudo apt install -y nodejs

Funnily enough, the one thing that's still not working is the test script from above (which did work before I re-did everything), but I daren't change anything now and tempt fate!

codetheweb commented 6 years ago

Huh, strange. node -v reports v8?

lswee commented 6 years ago

Hm, yeah…

$ node -v v8.11.2

On 10 Jun 2018, at 15:28, Max Isom notifications@github.com wrote:

Huh, strange. node -v reports v8?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/codetheweb/homebridge-tuya-outlet/issues/19#issuecomment-396053520, or mute the thread https://github.com/notifications/unsubscribe-auth/AmL_AE-0dYwcUFulXczSkHczMbmfv5WQks5t7S0IgaJpZM4UfGUt.