Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable To Link #2

Closed
dlashua opened this issue Aug 15, 2018 · 8 comments
Closed

Unable To Link #2

dlashua opened this issue Aug 15, 2018 · 8 comments

Comments

@dlashua
Copy link

dlashua commented Aug 15, 2018

I'm trying to use "tuya-cli link-wizard".

I fill out all the information and eventually get a "Error: Timed out wating for device(s) to connect to cloud".

But, then I realized... the Tuya device is not connected to any network. How will tuyapi/cli or tuyapi/link communicate with it? Am I supposed to put the Tuya Device into AP mode and then connect to its WiFi SSID before attempting the link-wizard?

I know the Android Tuya app is able to register the device without it being in AP mode, but I also see the WiFi status of my Android device change as it's doing this. And, in looking over the code in tuyapi/link, I don't see any place where it's even attempting to do that. It's simply sending UDP packets to the broadcast address.

Please advise.

@codetheweb
Copy link
Member

Tuya devices cleverly take advantage of two facts:

  • WiFi adapters can broadcast UDP packets of variable length when the said adapter is in any state. The adapter can be connected to a network, or just powered on.
  • It's very easy to sniff packet lengths (with or without being connected to a network).

So setup data is encoded into the UDP packet lengths themselves, which devices then sniff.

If you provide the output of DEBUG=* tuya-cli link-wizard I can help.

(Credit for reverse engineering the protocol and providing POC code goes to @BillSobel.)

@dlashua
Copy link
Author

dlashua commented Aug 15, 2018 via email

@BillSobel
Copy link

BillSobel commented Aug 15, 2018 via email

@dlashua
Copy link
Author

dlashua commented Aug 15, 2018 via email

@codetheweb
Copy link
Member

@dlashua what kind of device are you trying to link?

I've experienced devices sometimes refusing to respond to the linking process until I restart them. If possible, restart your device and try again.

Also, there are two linking modes. The one we want is (usually) activated by holding down a button for ~5 seconds, the one we don't want (AP mode) is activated by holding down a button for ~10 seconds. Make sure you don't hold it for too long. Specific instructions for your device on putting it in linking mode can be found in the Tuya app.

@dlashua
Copy link
Author

dlashua commented Aug 15, 2018

It's a Potensic Branded Electrical Plug module.

I've unplugged it and plugged it back in many many times.

I know SOMETHING is working, because it removes the device from my Tuya App every time I tried it. And I know the device works okay, because I'm able to add it back to the Tuya App.

On my device, a slow blinking LED is AP Mode and a Fast Blinking LED is "EZ Mode", which is what I think we want. I've tried both, just to be safe, and neither work with tuyapi/cli.

@dlashua
Copy link
Author

dlashua commented Aug 15, 2018

So it must be my router. I moved execution to a wirelessly connected computer, and after a few attempts it seems to have worked. The first time, I could hear the device relay click like it was going to work, but it never did. So I unplugged, replugged, and tried again. Then it worked and returned the JSON formatted data I was expecting.

@dlashua dlashua closed this as completed Aug 15, 2018
@codetheweb
Copy link
Member

Glad it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants