codetheweb / tuyapi

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

tuya-cli list-app does not print out a QR-Code #108

Closed carsten-h closed 6 years ago

carsten-h commented 6 years ago

I did all the things mentioned on https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md

This is what I got:

sudo npm i @tuyapi/cli -g npm WARN deprecated clipboard-js@0.3.6: Please migrate to https://github.com/lgarron/clipboard-polyfill /usr/local/bin/tuya-cli -> /usr/local/lib/node_modules/@tuyapi/cli/cli.js npm WARN svg-inline-react@1.0.3 requires a peer of react@^0.14.0 || ^15.0.0 but none is installed. You must install peer dependencies yourself.

+ @tuyapi/cli@1.4.1 added 386 packages from 353 contributors in 404.522s

sudo npm i anyproxy -g npm WARN deprecated clipboard-js@0.3.6: Please migrate to https://github.com/lgarron/clipboard-polyfill /usr/local/bin/anyproxy-ca -> /usr/local/lib/node_modules/anyproxy/bin/anyproxy-ca /usr/local/bin/anyproxy -> /usr/local/lib/node_modules/anyproxy/bin/anyproxy npm WARN svg-inline-react@1.0.3 requires a peer of react@^0.14.0 || ^15.0.0 but none is installed. You must install peer dependencies yourself.

+ anyproxy@4.0.12 added 240 packages from 273 contributors in 244.663s

sudo anyproxy-ca detecting CA status... AnyProxy CA does not exist. ? Would you like to generate one ? Yes temp certs cleared rootCA generated PLEASE TRUST the rootCA.crt in /root/.anyproxy/certificates The cert is generated at /root/.anyproxy/certificates. Please trust the rootCA.crt.

sudo tuya-cli list-app (node:2765) UnhandledPromiseRejectionWarning: RangeError: Array buffer allocation failed at new ArrayBuffer () at Object. (/usr/local/lib/node_modules/@tuyapi/cli/node_modules/brotli/build/encode.js:21:207) at Module._compile (internal/modules/cjs/loader.js:707:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10) at Module.load (internal/modules/cjs/loader.js:605:32) at tryModuleLoad (internal/modules/cjs/loader.js:544:12) at Function.Module._load (internal/modules/cjs/loader.js:536:3) at Module.require (internal/modules/cjs/loader.js:643:17) at require (internal/modules/cjs/helpers.js:22:18) at Object. (/usr/local/lib/node_modules/@tuyapi/cli/node_modules/brotli/compress.js:1:76) at Module._compile (internal/modules/cjs/loader.js:707:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10) at Module.load (internal/modules/cjs/loader.js:605:32) at tryModuleLoad (internal/modules/cjs/loader.js:544:12) at Function.Module._load (internal/modules/cjs/loader.js:536:3) at Module.require (internal/modules/cjs/loader.js:643:17) (node:2765) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:2765) [DEP0018] 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.

There was no QR-code printed out by tuya-cli list-app. What am I doing wrong?

I have it installed on a Raspberry Pi zero W with Rasbian Strech lite.

Thank you for help!

codetheweb commented 6 years ago

Can you please provide the output of node -v?

carsten-h commented 6 years ago

Sure, this is: v11.1.0

Am 10.11.2018 um 16:52 schrieb Max Isom notifications@github.com:

Can you please provide the output of node -v?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/codetheweb/tuyapi/issues/108#issuecomment-437593390, or mute the thread https://github.com/notifications/unsubscribe-auth/AqTkfIEYASmNNTC5vHtevgQSsEcmnPYGks5utvYxgaJpZM4YX-Jo.

codetheweb commented 6 years ago

Ok, so it's up to date.

The error looks like the Raspberry Pi is running out of RAM. Are you able to try using it on Windows or macOS?

carsten-h commented 6 years ago

It is only a Pi zero W and I have homebridge and pi-hole running. Maybe this is too much?

carsten-h commented 6 years ago

I stopped pi-hole and now I get the QR-Code and the settings for the proxy. This is working. I can install the certificate in my iPhone and I can set the proxy to the given parameters (IP address of the Pi and port 8001).

If I try to reach anything on my iphone in the browser I am getting an error message, that there is no connection to this server. Also the Smartlife App is showing me a network error. So the process is not working. I will search what can be also wrong. I still can switch the tuya outlet with the Smartlife App.

It seems the proxy can not reach the outside world.

carsten-h commented 6 years ago

I saw the other issue where no data is send through the proxy. I did what you asked there:

[AnyProxy WARN][2018-11-11 10:16:44]: ROOT CA NOT INSTALLED YET [AnyProxy Log][2018-11-11 10:16:44]: The root CA file path is: /root/.anyproxy/certificates/rootCA.crt [AnyProxy Log][2018-11-11 10:17:00]: Http proxy started on port 8001 [AnyProxy Log][2018-11-11 10:17:00]: web interface started on port 8002 [AnyProxy Log][2018-11-11 10:17:22]: received https CONNECT request www.google.de [AnyProxy Log][2018-11-11 10:17:22]: will forward to local https server [AnyProxy Log][2018-11-11 10:17:22]: [internal https]proxy server for www.google.de established [AnyProxy Log][2018-11-11 10:17:22]: received https CONNECT request www.google.de [AnyProxy Log][2018-11-11 10:17:22]: will forward to local https server [AnyProxy Log][2018-11-11 10:17:22]: [internal https]proxy server for www.google.de established [AnyProxy Log][2018-11-11 10:17:22]: received https CONNECT request www.google.de [AnyProxy Log][2018-11-11 10:17:22]: will forward to local https server ^C[AnyProxy Log][2018-11-11 10:18:01]: destorying https connection : 127.0.0.1:38257 [AnyProxy Log][2018-11-11 10:18:01]: endding https cltSocket : 127.0.0.1:38257 [AnyProxy Log][2018-11-11 10:18:01]: clearing cache file... [AnyProxy Log][2018-11-11 10:18:01]: ==>>> clearing cache [AnyProxy Log][2018-11-11 10:18:01]: closing webserver...

This is what happen when using Smartlife App:

[AnyProxy WARN][2018-11-11 11:15:03]: ROOT CA NOT INSTALLED YET [AnyProxy Log][2018-11-11 11:15:03]: The root CA file path is: /root/.anyproxy/certificates/rootCA.crt [AnyProxy Log][2018-11-11 11:15:20]: Http proxy started on port 8001 [AnyProxy Log][2018-11-11 11:15:20]: web interface started on port 8002 [AnyProxy Log][2018-11-11 11:15:21]: received https CONNECT request a1.tuyaeu.com [AnyProxy Log][2018-11-11 11:15:21]: received https CONNECT request ios.bugly.qq.com [AnyProxy Log][2018-11-11 11:15:21]: will forward to local https server [AnyProxy Log][2018-11-11 11:15:21]: will forward to local https server [AnyProxy Log][2018-11-11 11:15:21]: [internal https]proxy server for a1.tuyaeu.com established [AnyProxy Log][2018-11-11 11:15:21]: [internal https]proxy server for ios.bugly.qq.com established [AnyProxy Log][2018-11-11 11:15:22]: received https CONNECT request a1.tuyaeu.com [AnyProxy Log][2018-11-11 11:15:22]: will forward to local https server [AnyProxy Log][2018-11-11 11:15:22]: [internal https]proxy server for a1.tuyaeu.com established [AnyProxy Log][2018-11-11 11:15:26]: received https CONNECT request a1.tuyaeu.com [AnyProxy Log][2018-11-11 11:15:26]: will forward to local https server [AnyProxy Log][2018-11-11 11:15:26]: [internal https]proxy server for a1.tuyaeu.com established [AnyProxy Log][2018-11-11 11:15:27]: received https CONNECT request a1.tuyaeu.com [AnyProxy Log][2018-11-11 11:15:27]: will forward to local https server [AnyProxy Log][2018-11-11 11:15:27]: [internal https]proxy server for a1.tuyaeu.com established [AnyProxy Log][2018-11-11 11:15:27]: received https CONNECT request gateway.icloud.com [AnyProxy Log][2018-11-11 11:15:28]: will forward to local https server [AnyProxy Log][2018-11-11 11:15:28]: [internal https]proxy server for gateway.icloud.com established

I don't know if this helps. When I call http://192.168.178.38:8001 from Safari on my iPhone I am getting: [ERROR]: Unable to parse results from queryads.php: Unhandled error message (Invalid domain!)

This seems to be something from pi-hole. I will search if I can switch it off completeley.

I switched all the services from pi-hole off completely and nothing changed. The messages I am getting are still the same.

codetheweb commented 6 years ago

Looks like AnyProxy is complaining that the root CA certificate isn't installed, which would result in the behavior you're experiencing. Did you run anyproxy-ca to generate the certificate (may need to prefix that command with sudo)?

carsten-h commented 6 years ago

I wrote in one message above this:

sudo anyproxy-ca detecting CA status... AnyProxy CA does not exist. ? Would you like to generate one ? Yes temp certs cleared rootCA generated PLEASE TRUST the rootCA.crt in /root/.anyproxy/certificates The cert is generated at /root/.anyproxy/certificates. Please trust the rootCA.crt.

I thought that this installed the root CA certificate. I read the QR-Code it with my iPhone and installed this certificate on it. Or do I also have to do one step more in the raspberry pi?

codetheweb commented 6 years ago

It looks like since you're using sudo to install the root certificate it's going in the root user's directory. Try running sudo tuya-cli list-app and see what happens.

carsten-h commented 6 years ago

Yes, I am using sudo because otherwise it was not working. I also used sudo for tuya-cli.

This is the certificate I installed on my iPhone: img_34ffecbb9097-1

carsten-h commented 6 years ago

I did a freah install of anyproxy:

sudo npm i anyproxy -g npm WARN deprecated clipboard-js@0.3.6: Please migrate to https://github.com/lgarron/clipboard-polyfill /usr/local/bin/anyproxy-ca -> /usr/local/lib/node_modules/anyproxy/bin/anyproxy-ca /usr/local/bin/anyproxy -> /usr/local/lib/node_modules/anyproxy/bin/anyproxy npm WARN svg-inline-react@1.0.3 requires a peer of react@^0.14.0 || ^15.0.0 but none is installed. You must install peer dependencies yourself.

+ anyproxy@4.0.12 removed 3 packages and updated 2 packages in 93.064s

Then this:

sudo anyproxy-ca detecting CA status... AnyProxy CA exists, but not be trusted ? Would you like to open the folder and trust it ? Yes

Then this:

sudo anyproxy -i [AnyProxy WARN][2018-11-12 15:27:43]: ROOT CA NOT INSTALLED YET [AnyProxy Log][2018-11-12 15:27:43]: The root CA file path is: /root/.anyproxy/certificates/rootCA.crt [AnyProxy Log][2018-11-12 15:27:59]: Http proxy started on port 8001 [AnyProxy Log][2018-11-12 15:27:59]: web interface started on port 8002 AnyProxy Log][2018-11-12 15:28:19]: received https CONNECT request www.google.de [AnyProxy Log][2018-11-12 15:28:19]: will forward to local https server [AnyProxy Log][2018-11-12 15:28:19]: [internal https]proxy server for www.google.de established [AnyProxy Log][2018-11-12 15:28:19]: received https CONNECT request www.google.de [AnyProxy Log][2018-11-12 15:28:19]: will forward to local https server ^C[AnyProxy Log][2018-11-12 15:29:16]: destorying https connection : 127.0.0.1:33499 [AnyProxy Log][2018-11-12 15:29:16]: endding https cltSocket : 127.0.0.1:33499 [AnyProxy Log][2018-11-12 15:29:16]: clearing cache file... [AnyProxy Log][2018-11-12 15:29:16]: ==>>> clearing cache [AnyProxy Log][2018-11-12 15:29:16]: closing webserver...

Then this:

sudo npm i @tuyapi/cli -g npm WARN deprecated clipboard-js@0.3.6: Please migrate to https://github.com/lgarron/clipboard-polyfill /usr/local/bin/tuya-cli -> /usr/local/lib/node_modules/@tuyapi/cli/cli.js npm WARN svg-inline-react@1.0.3 requires a peer of react@^0.14.0 || ^15.0.0 but none is installed. You must install peer dependencies yourself.

+ @tuyapi/cli@1.4.1 removed 3 packages and updated 3 packages in 131.518s

The strange thing is that anyproxy is telling this: "AnyProxy CA exists, but not be trusted" and this: "AnyProxy CA exists, but not be trusted" or is this normal?

carsten-h commented 6 years ago

Oh my god, I saw the thing in the other thread I was missing to do. I also didn't set the Certificate trust settings.

Now I am one step further. When I call google.de in Safari on my iPhone I am getting: img_f3bb350fff2b-1

And the Smartlife App is still showing the same error.

carsten-h commented 6 years ago

Hmm, strange. I stiil get the error in the Smartlife App, but tuyapi-cli prints me out two id/key pairs. Is it normal that the id/key pair is also printed for devices that are not online?

And also I had it five times now that the call to "tuyapi-cli list-app" is showing me only this:

bildschirmfoto 2018-11-12 um 21 54 23

I had to kill the ssh connection as CTRL-C is not working.

Thank you for your help so far! I am so stupid, that I didn't see the trusting of the certificate in the instructions.

codetheweb commented 6 years ago

@carsten-h no problem.

It will show devices that are offline because it just intercepts the Tuya cloud response which includes all devices.

You should see key/ID pairs being printed out, then an error will pop up in the app because the proxy is killed. Sounds like it's working.

carsten-h commented 6 years ago

Ah, OK I see. Then this is clear.

Do you know why the tuya-cli output stops in the middle of the QR-code? Is this also a problem of too less RAM?

codetheweb commented 6 years ago

Not sure what you mean, are you saying that you don't see a spinner and the text "Waiting for request..." or something similar? If so, it could be a RAM issue but I'm not sure.

carsten-h commented 6 years ago

Yes, the output stops at this point. There is no more reaction in this SSH session.

But today I installed homebridge-tuya and both devices worked without any problem! Thank you for you great work and support!

One question at last: Is the plugin working completely in the local net to switch the outlets? So I can cut them off from internet?

codetheweb commented 6 years ago

Yes, it's completely local. It doesn't talk with Tuya's cloud servers at all.