Closed rbyers8252 closed 6 years ago
@rbyers8252 everything sounds good...
I'm not sure what shell you're using on Windows, but can you please set the environment variable DEBUG
to *
, run the linking wizard again, and post the output?
Very strangely, setting the environment var DEBUG to * already did the trick for me.
Not an expert with all of this. Been a long time since I did a bunch of this. How do I set the environment var debug to * ?
I managed to find it for windows cmd SET DEBUG= or $env:DEBUG = "" for powershell I have the same error and I got a minute of this.
`- Registering devices(s)... @tuyapi/cloud Sending parameters: +202ms @tuyapi/cloud { a: 'tuya.m.device.list.token', @tuyapi/cloud deviceId: '6kkpgqusqcttueoa3502kj6vujbd0pya64u7t7l3k5h4', @tuyapi/cloud os: 'Linux', @tuyapi/cloud lang: 'en', @tuyapi/cloud v: '1.0', @tuyapi/cloud clientId: 'my ios app key', @tuyapi/cloud time: 1534504445, @tuyapi/cloud postData: '{"token":"cWW0KWZt"}', @tuyapi/cloud sid: 'az15344262526951vjKzyby31f70b89116d7c63518372b15a642803f', @tuyapi/cloud sign: 'dd7454007571175f79633aa0766a611f' } +3ms
with no registration
If I register it through the app is it the
@tuyapi/cloud deviceId: '6kkpgqusqcttueoa3502kj6vujbd0pya64u7t7l3k5h4', that I need to use the API?
@BenjaminKauer if possible, could you run a few tests and see if setting DEBUG=*
is the only reason it worked? If so, that's a rather strange bug that needs to be fixed.
@stephenmhall what's your configuration? Does the computer you're running the tool from have a (enabled) wireless card?
Sometimes devices get "stuck", and unplugging then plugging them back in seems to help.
@stephenmhall what's your configuration? Does the computer you're running the tool from have a (enabled) wireless card?
Ok can I assume from this my PC has to be on the wifi not lan? Now I think about it of course it needs a wifi connection as it will need to connect to the plug before it gets placed on my network. Sorry fundamental misunderstanding from me there. I have wifi but disabled, I will have another go.
well, a lot of it looks to be working but it never registers.
`- Registering devices(s)... @tuyapi/cloud Sending parameters: +0ms @tuyapi/cloud { a: 'tuya.m.user.email.register', @tuyapi/cloud deviceId: '5fpd9gbt61dgwr5vz2y70xcj5xuj3e0xdqt5vqtnawht', @tuyapi/cloud os: 'Linux', @tuyapi/cloud lang: 'en', @tuyapi/cloud v: '1.0', @tuyapi/cloud clientId: 'myID', @tuyapi/cloud time: 1534584771, @tuyapi/cloud postData: '{"countryCode":"AZ","email":"johndoe@example.com","passwd":"8ac4253450b2e0eccdfe0fa24036b6d5"}', @tuyapi/cloud sign: 'ae425b03f88f2fadf1fa6015d14aa676' } +2ms | Registering devices(s)... @tuyapi/cloud Received response: +858ms @tuyapi/cloud {"t":1534584773312,"success":false,"errorCode":"USER_NAME_IS_EXIST","status":"error","errorMsg":"Username exists."} @tuyapi/cloud +4ms @tuyapi/cloud Sending parameters: +3ms @tuyapi/cloud { a: 'tuya.m.user.email.password.login', @tuyapi/cloud deviceId: '5fpd9gbt61dgwr5vz2y70xcj5xuj3e0xdqt5vqtnawht', @tuyapi/cloud os: 'Linux', @tuyapi/cloud lang: 'en', @tuyapi/cloud v: '1.0', @tuyapi/cloud clientId: 'myID', @tuyapi/cloud time: 1534584772, @tuyapi/cloud postData: '{"countryCode":"AZ","email":"johndoe@example.com","passwd":"8ac4253450b2e0eccdfe0fa24036b6d5"}', @tuyapi/cloud sign: '0e79cffff18b546803ceec5c6c2e57e9' } +1ms | Registering devices(s)... @tuyapi/cloud Received response: +578ms @tuyapi/cloud {"result":{"timezone":"","tempUnit":1,"sid":"az153442r2526951vxKzybb3e55dda0f3008986a3d2e77ca1881d5b5","uid":"az1534422526951vKzyb","nickname":"","phoneCode":"AZ","email":"johndoe@example.com","snsNickname":"","improveCompanyInfo":false,"dataVersion":0,"sex":0,"accountType":1,"mobile":"","headPic":"","ecode":"z5z453311141424z","domain":{"deviceHttpUrl":"http://a.tuyaus.com","deviceHttpsUrl":"https://a2.tuyaus.com","deviceMediaMqttUrl":"s.tuyaus.com","deviceMqttsUrl":"m2.tuyaus.com","gwApiUrl":"http://a.gw.tuyaus.com/gw.json","gwMqttUrl":"mq.gw.tuyaus.com","mobileApiUrl":"https://a1.tuyaus.com","mobileMediaMqttUrl":"s.tuyaus.com","mobileMqttUrl":"mq.mb.tuyaus.com","mobileMqttsUrl":"m1.tuyaus.com","pxApiUrl":"http://px.tuyaus.com","regionCode":"AZ"},"timezoneId":"","userType":1,"partnerIdentity":"p1095947","username":"johndoe@example.com"},"t":1534584773911,"success":true,"status":"ok"} @tuyapi/cloud +4ms @tuyapi/cloud Sending parameters: +3ms @tuyapi/cloud { a: 'tuya.m.device.token.create', @tuyapi/cloud deviceId: '5fpd9gbt61dgwr5vz2y70xcj5xuj3e0xdqt5vqtnawht', @tuyapi/cloud os: 'Linux', @tuyapi/cloud lang: 'en', @tuyapi/cloud v: '1.0', @tuyapi/cloud clientId: 'myID', @tuyapi/cloud time: 1534584773, @tuyapi/cloud postData: '{"timeZone":"-05:00"}', @tuyapi/cloud sid: 'az153442r2526951vxKzybb3e55dda0f3008986a3d2e77ca1881d5b5', @tuyapi/cloud sign: 'd8af7efbc00f1722c04fe150e0ece126' } +1ms / Registering devices(s)... @tuyapi/cloud Received response: +547ms @tuyapi/cloud {"result":{"secret":"WU1C","token":"M4byJnXr"},"t":1534584774466,"success":true,"status":"ok"} @tuyapi/cloud +1ms @tuyapi/link:wizard Token: { secret: 'WU1C', token: 'M4byJnXr' } +0ms @tuyapi/link:manual Sending SmartLink initialization packets +0ms @tuyapi/link:wizard Polling cloud for details on token... +5ms @tuyapi/cloud Sending parameters: +12ms @tuyapi/cloud { a: 'tuya.m.device.list.token', @tuyapi/cloud deviceId: '5fpd9gbt61dgwr5vz2y70xcj5xuj3e0xdqt5vqtnawht', @tuyapi/cloud os: 'Linux', @tuyapi/cloud lang: 'en', @tuyapi/cloud v: '1.0', @tuyapi/cloud clientId: 'myID', @tuyapi/cloud time: 1534584773, @tuyapi/cloud postData: '{"token":"M4byJnXr"}', @tuyapi/cloud sid: 'az153442r2526951vxKzybb3e55dda0f3008986a3d2e77ca1881d5b5', @tuyapi/cloud sign: 'ae16b8a5a59f20c9787b0e1a7785aa86' } +1ms / Registering devices(s)... @tuyapi/cloud Received response: +544ms @tuyapi/cloud {"result":[],"t":1534584775017,"success":true,"status":"ok"} @tuyapi/cloud +4ms
Then what looks to be 37 seconds later.
`| Registering devices(s)... @tuyapi/cloud Received response: +591ms @tuyapi/cloud {"result":[],"t":1534584817699,"success":true,"status":"ok"} @tuyapi/cloud +4ms / Registering devices(s)... @tuyapi/link:manual Finished sending packets. +38s
Then the same lines over and over for another 107 seconds until, sorry couldnt get the next block to format.
| Registering devices(s)... @tuyapi/cloud Sending parameters: +204ms @tuyapi/cloud { a: 'tuya.m.device.list.token', @tuyapi/cloud deviceId: '5fpd9gbt61dgwr5vz2y70xcj5xuj3e0xdqt5vqtnawht', @tuyapi/cloud os: 'Linux', @tuyapi/cloud lang: 'en', @tuyapi/cloud v: '1.0', @tuyapi/cloud clientId: 'myID', @tuyapi/cloud time: 1534584924, @tuyapi/cloud postData: '{"token":"M4byJnXr"}', @tuyapi/cloud sid: 'az153442r2526951vxKzybb3e55dda0f3008986a3d2e77ca1881d5b5', @tuyapi/cloud sign: '2217ac6a22004d3e69a19495f69635a2' } +4ms | Registering devices(s)... @tuyapi/cloud Received response: +500ms @tuyapi/cloud {"result":[],"t":1534584925516,"success":true,"status":"ok"} @tuyapi/cloud +4ms Device(s) failed to be registered! Error: Timed out wating for device(s) to connect to cloud at Promise (C:\Users\Stephen\AppData\Roaming\npm\node_modules\@tuyapi\cli\node_modules\@tuyapi\cloud\index.js:275:12) at <anonymous>
After all this it might be a faulty unit. I can't register it using the Smart Life app either. Came as a pair and the first one registered fine on the app.
I got this after 116 seconds trying the pre registered one. It did however remove it from the app. It was re discovered by the app ok.
× Device(s) failed to be registered! { HTTPError: Response code 400 (Bad Request) at stream.catch.then.data (C:\Users\Stephen\AppData\Roaming\npm\node_modules\@tuyapi\cli\node_modules\got\index.js:386:13) at <anonymous> at process._tickCallback (internal/process/next_tick.js:118:7) name: 'HTTPError', host: 'a1.tuyaus.com', hostname: 'a1.tuyaus.com', method: 'GET', path: '/api.json?a=tuya.m.device.list.token&deviceId=t4kisxbdd4jxf7vyt74qgg3qa3ba56ywjho27ozwon46&os=Linux&lang=en&v=1.0&clientId=n87gvu8wapamy9jyqp3q&time=1534592956&postData=%7B%22token%22%3A%22c5eWa3yj%22%7D&sid=az153442l2526951vHKzybK31984620d3bcd8f72b8b93b3e0a771f1d&sign=f63352d342c8e96250e79c709a5f20a1', protocol: 'https:', url: 'https://a1.tuyaus.com/api.json', statusCode: 400, statusMessage: 'Bad Request', headers: { date: 'Sat, 18 Aug 2018 11:49:17 GMT', server: 'Apache-Coyote/1.1', 'content-length': '0', connection: 'Close' } }
@stephenmhall are you in the U.S.? If not, your issue may stem from Tuya wanting you to use a different endpoint/server than the default. I just realized this in a different issue.
No I'm in the UK. So I presume I need to edit some of the default details in tuya-cli? I see the endpoints are coded into the cloud/index.js file, does the link-wizard need some extra code to select endpoint when registering.
I'm also having a similar problem and am in the UK, I am able to use the Tuya app on my phone to register it without issue but I get this when trying to do it this way:
Matts-MacBook-Pro:~ matt$ tuya-cli link-wizard ? Make the indicator light on your device flash. For most devices, this means holding down the main button. Press return when it's blinking. Yes ? What's your WiFi called? WIFI1111 ? What's the password for your WiFi? [hidden] ? How many devices do you want to link? 1 ? Do you want to save devices that are successfully linked? Yes ✖ Device(s) failed to be registered! Error: Timed out wating for device(s) to connect to cloud at Promise (/usr/local/lib/node_modules/@tuyapi/cli/node_modules/@tuyapi/cloud/index.js:275:12)
For those in the UK: try the instructions below to see if the error is related to your region.
git clone https://github.com/TuyaAPI/link.git
or downloading a zipped version of the master branch from Github.cd link
on *nix) and create a new file called dev.js
with the contents below:const TuyaLink = require('./index.js');
const register = new TuyaLink.wizard({apiKey: '<your-api-key>',
apiSecret: '<your-api-secret>',
email: 'example@example.com', password: 'example-password',
region: 'EU'});
register.init().then(sid => {
register.linkDevice({ssid: '<your-ssid>', wifiPassword: '<your-wifi-password>'}).then(devices => {
console.log(devices)
});
}).catch(err => {
console.log(err)
});
Replace the <*>
placeholders with the appropriate values (the email
and password
parameters don't really matter).
Run npm i
to install dependencies.
Run DEBUG=* node dev.js
and paste the results.
Hi Team,
I am also facing similar issue, while running "tuya-cli link-wizard". It is throwing error in registering the plug with timeout error message.
I
bought plugs from China and it works well with Smart Life app and I am using these plugs in Norway..later it would be used in India also :).
Error
✖ Device(s) failed to be registered! Error: Timed out wating for device(s) to connect to cloud at Promise (/usr/local/lib/node_modules/@tuyapi/cli/node_modules/@tuyapi/cloud/index.js:275:12)
I'm experiencing the same issue in the states, I attempt to register but it times out waiting for it to connect to the cloud. I have this Tonbux power strip but haven't tried setting it up with an app (I was hoping to avoid that)
DEBUG=*
didn't seem to change anything, I get the same repeated lines detailed above.
Has anyone in this thread:
I was getting the same timeout problem trying to register my bulb from a Raspberry Pi here in the UK. Many thanks for posting the code above - now says it's registered fine.
I tried registering my device three times (the third time I unplugged and plugged the device back in while the link wizard ran), didn't work. I then tried with DEBUG=*
and it worked for me 🤷♀️
Hello, Sadly, I was not that successful. I too am getting the "timeout waiting for device(s)" message. I did try pasting the code into dev.js Sadly, this one almost instantly fails with an error, saying my session had expired. As I copy-pasted all the necessary items, I don't think I made a typo. These are the last lines appearing in the debug: @tuyapi/cloud { a: 'tuya.m.device.token.create', @tuyapi/cloud deviceId: 'emcg84ujrzo19pltd1x7yxwoo2fe9wnn87o0cggzrems', @tuyapi/cloud os: 'Linux', @tuyapi/cloud lang: 'en', @tuyapi/cloud v: '1.0', @tuyapi/cloud clientId: 'p8fcw87cepukt98u5rnh', @tuyapi/cloud time: 1535828794, @tuyapi/cloud postData: '{"timeZone":"-05:00"}', @tuyapi/cloud sid: 'az153582M80686451rLRjro3c47a810b55d3f0b46e342acd89f9dd1e ', @tuyapi/cloud sign: 'cff1f48e5e76b7ce51a90fa5aada5285' } +1ms @tuyapi/cloud Received response: +218ms @tuyapi/cloud {"t":1535828794017,"success":false,"errorCode":"USER_SESSION_INV ALID","status":"error","errorMsg":"Session Expired, please log in again"}
Is there anything I can try / check? I am in Switzerland, so I guess EU as a region is correct.
Besides the region parameter, the other one that might affect stuff is the timezone.
@the-swissionary @amitn16 @lanceuppercut47 @stephenmhall
Try adjusting the timezone parameter in the below code with your UTC offset and see if it works:
const TuyaLink = require('./index.js');
const register = new TuyaLink.wizard({apiKey: '<your-api-key>',
apiSecret: '<your-api-secret>',
timezone: '-05:00',
email: 'example@example.com', password: 'example-password',
region: 'EU'});
register.init().then(sid => {
register.linkDevice({ssid: '<your-ssid>', wifiPassword: '<your-wifi-password>'}).then(devices => {
console.log(devices)
});
}).catch(err => {
console.log(err)
});
I've been able to register the device twice, but it takes a few hours of trying to connect. I tried changing the timezone but it's just as finicky. The default region should be ok since I'm in the US.
Huh. I'm really confused because it works flawlessly for me every single time.
Well, I tried the new code you sent me (try to reply to your message via email, but somehow, my reply must have gotten stuck).
Sadly, adjusting the time zone to "02:00" and to "01:002 alone did not fix the "session expoired" error.
However, I experimentally tried to change the region code to "AZ" - because in the debug log, I saw that one been returned by what I guess was the tuya server.
Setting the region code to "AZ" at least does not give me the "session expired" message anymore, and the dev.js script runs perfectly.
Sadly, it still would not recognize or register my device. :-(
Mostly, the debug log shows this in repeat:
@tuyapi/cloud Sending parameters: +205ms
@tuyapi/cloud { a: 'tuya.m.device.list.token',
@tuyapi/cloud deviceId: 'd6pxx9dleh9ky0sivwy559v6mpchfr1axlhzgxzcio38',
@tuyapi/cloud os: 'Linux',
@tuyapi/cloud lang: 'en',
@tuyapi/cloud v: '1.0',
@tuyapi/cloud clientId: 'p8fcw87cepukt98u5rnh',
@tuyapi/cloud time: 1535832118,
@tuyapi/cloud postData: '{"token":"sjz1FO1p"}',
@tuyapi/cloud sid: 'az153574f0632470K9iQHQM39ef18d02eb85dfa875fd1dc7404d51f6
',
@tuyapi/cloud sign: 'd81405b15dce2e4d3db93fe3172977e2' } +0ms
@tuyapi/cloud Received response: +610ms
@tuyapi/cloud {"result":[],"t":1535832118572,"success":true,"status":"ok"}
@tuyapi/cloud +0ms
@tuyapi/cloud Sending parameters: +207ms
...
and so on.
What I don't see in the debug at all any sign of tuya-cli trying to somehow scan my wlan for a tuya device.
This makes me wonder: Is there anything I have to configure in my wlan settings?
curently, the raspberry pi connects to my network using its built-in wlan adapter.
Is that ok? Or does the wlan adapter have to remain not connected?
No joy here in UK. Tried EU region code:
@tuyapi/cloud Sending parameters: +0ms @tuyapi/cloud { a: 'tuya.m.user.email.register', @tuyapi/cloud deviceId: '5cf84u0il716lsutflgtb6wjk40r8xwdq18n3s65si4w', @tuyapi/cloud os: 'Linux', @tuyapi/cloud lang: 'en', @tuyapi/cloud v: '1.0', @tuyapi/cloud clientId: '**', @tuyapi/cloud time: 1535886159, @tuyapi/cloud postData: @tuyapi/cloud '{"countryCode":"EU","email":"example@example.com","passwd":"cc4436eff149ba9761aaac07b36360ea"}', @tuyapi/cloud sign: '2aa222ade568b747f1d0e49d9d2eb85a' } +1ms @tuyapi/cloud Received response: +529ms @tuyapi/cloud {"t":1535886159131,"success":false,"errorCode":"USER_NAME_IS_EXIST","status":"error","errorMsg":"Username exists."} @tuyapi/cloud +0ms @tuyapi/cloud Sending parameters: +1ms @tuyapi/cloud { a: 'tuya.m.user.email.password.login', @tuyapi/cloud deviceId: '5cf84u0il716lsutflgtb6wjk40r8xwdq18n3s65si4w', @tuyapi/cloud os: 'Linux', @tuyapi/cloud lang: 'en', @tuyapi/cloud v: '1.0', @tuyapi/cloud clientId: '*', @tuyapi/cloud time: 1535886159, @tuyapi/cloud postData: @tuyapi/cloud '{"countryCode":"EU","email":"example@example.com","passwd":"cc4436eff149ba9761aaac07b36360ea"}', @tuyapi/cloud sign: 'b35d6b5cc1fbb64c1f6e77d6a9779dfc' } +0ms @tuyapi/cloud Received response: +916ms @tuyapi/cloud {"result":{"dataVersion":0,"timezone":"","sex":0,"accountType":1,"tempUnit":1,"mobile":"","headPic":"","sid":"az153588y5226667Csa4XsJ3e7e236f98de40c9e36a5b2d673afb8a5","ecode":"z2z555yy55118888","uid":"az1535885226667Ca4Xs","domain":{"gwApiUrl":"http://a.gw.tuyaus.com/gw.json","mobileApiUrl":"https://a1.tuyaus.com","regionCode":"AZ","deviceHttpUrl":"http://a.tuyaus.com","mobileMqttUrl":"mq.mb.tuyaus.com","deviceMediaMqttUrl":"s.tuyaus.com","pxApiUrl":"http://px.tuyaus.com","deviceHttpsUrl":"https://a2.tuyaus.com","deviceMqttsUrl":"m2.tuyaus.com","gwMqttUrl":"mq.gw.tuyaus.com","mobileMediaMqttUrl":"s.tuyaus.com","mobileMqttsUrl":"m1.tuyaus.com"},"nickname":"","phoneCode":"EU","timezoneId":"","userType":1,"partnerIdentity":"p1107934","email":"example@example.com","snsNickname":"","improveCompanyInfo":false,"username":"example@example.com"},"t":1535886160059,"success":true,"status":"ok"} @tuyapi/cloud +0ms @tuyapi/cloud Sending parameters: +2ms @tuyapi/cloud { a: 'tuya.m.device.token.create', @tuyapi/cloud deviceId: '5cf84u0il716lsutflgtb6wjk40r8xwdq18n3s65si4w', @tuyapi/cloud os: 'Linux', @tuyapi/cloud lang: 'en', @tuyapi/cloud v: '1.0', @tuyapi/cloud clientId: '***', @tuyapi/cloud time: 1535886160, @tuyapi/cloud postData: '{"timeZone":"+01:00"}', @tuyapi/cloud sid: 'az153588y5226667Csa4XsJ3e7e236f98de40c9e36a5b2d673afb8a5', @tuyapi/cloud sign: 'b5193a4f047e03944825ba398e765148' } +0ms @tuyapi/cloud Received response: +136ms @tuyapi/cloud {"t":1535886160283,"success":false,"errorCode":"USER_SESSION_INVALID","status":"error","errorMsg":"Session Expired, please log in again"}
Adding timezone didn't work either.
I am able to do that for tuyaapi but not able to integrate with openhab. follow following.. install npm & timeout.. follow the procedure given in below link. ( cleanup would be good ) and then install tuyaapi.
cd /etc/openhab2/scripts npm install codetheweb/tuyapi
https://github.com/unparagoned/njsTuya/blob/master/README.md
local key you have to find using capture packet. ( capture logs while connecting smart plug 1st time iwth Smartlife or any other similar app) other details you can get by running > python njstuyamonitor.py >
you would able to control switch through command line using it.. but openhab integration.. I am still struggling.. any clue..
@the-swissionary the state of your WiFi adapter shouldn't matter as long as it's enabled; the setup process works by broadcasting a series of UDP packets that are sniffed by Tuya devices.
For those who are still struggling to get it to work: do you hear your device "click" during an unsuccessful setup?
Mine doesn't click but I've given up using this new one until it's fixed, the old one works fine now that I know to assign an IP in the config.json
No, there's no click from my device either.
Hi, I am also in the UK and am having similar issues - I am on a Rasberry Pi, with a working homebridge set up controlling other platforms and accessories. My Pi is connected via ethernet, not wifi.
I used the dev.js file as suggested, got the session expired error and then tried the region AZ as suggested by @the-swissionary. This got the code working, but my devices never register. I can immediately register the same device with the Tuya app, so there's no issue there.
Thanks, Richard
@dickieblack are you able to run the linking wizard from a device that has a WiFi radio?
Hi, the Pi I am using does have Wi-Fi built in - its a model 3B. However, as it’s using the Ethernet connection it may not be active. Does it need to be connected via Wi-Fi for the link wizard to work?
I am using the following powerstrip by Meross https://www.amazon.de/Steckdosenleiste-Mehrfachsteckdose-Überspannungsschutz-Intelligenten-USB-Anschlüsse/dp/B079DNZP4T/ref=sr_1_1_sspa?ie=UTF8&qid=1535976878&sr=8-1-spons&keywords=meross+steckdosenleiste&psc=1.
It does not use the Smart Life App, but instead their own Meross App.
So I am not quite sure if it even works with Tuya Cloud. I didn't have any luck the first try.
Also got the following output:
✖ Device(s) failed to be registered! Error: Timed out wating for device(s) to connect to cloud at Promise (/usr/lib/node_modules/@tuyapi/cli/node_modules/@tuyapi/cloud/index.js:275:12) at <anonymous>
I applied the fixes to TuyaLink. Got the following output:
DEBUG=* node dev.js @tuyapi/cloud Sending parameters: +0ms @tuyapi/cloud { a: 'tuya.m.user.email.register', @tuyapi/cloud deviceId: 'e3rv1lg9tuptv3lorlhq53dxptghd8os9m50lu2xcxpe', @tuyapi/cloud os: 'Linux', @tuyapi/cloud lang: 'en', @tuyapi/cloud v: '1.0', @tuyapi/cloud clientId: 't9d59wv99mnpa89uh3e3', @tuyapi/cloud time: 1535976311, @tuyapi/cloud postData: '{"countryCode":"EU","email":"lars@besser-brinkum.de","passwd":"db492f0ed648738a8fe0fe36246b18bb"}', @tuyapi/cloud sign: '60e643e3c21e53d213d346ba7a32b075' } +9ms @tuyapi/cloud Received response: +921ms @tuyapi/cloud {"result":{"dataVersion":0,"sex":0,"tempUnit":1,"headPic":"","sid":"az153597j6311240LyPhmv83e80f8eac7ab9dc89419509be2a6857ef","ecode":"z3z55567395zz13a","uid":"az1535976311240LPhmv","domain":{"gwApiUrl":"http://a.gw.tuyaus.com/gw.json","mobileApiUrl":"https://a1.tuyaus.com","regionCode":"AZ","deviceHttpUrl":"http://a.tuyaus.com","mobileMqttUrl":"mq.mb.tuyaus.com","deviceMediaMqttUrl":"s.tuyaus.com","pxApiUrl":"http://px.tuyaus.com","deviceHttpsUrl":"https://a2.tuyaus.com","deviceMqttsUrl":"m2.tuyaus.com","gwMqttUrl":"mq.gw.tuyaus.com","mobileMediaMqttUrl":"s.tuyaus.com","mobileMqttsUrl":"m1.tuyaus.com"},"nickname":"","phoneCode":"EU","timezoneId":"","userType":1,"partnerIdentity":"p1108942","email":"hidden","snsNickname":"","improveCompanyInfo":false,"username":"hidden"},"t":1535976311403,"success":true,"status":"ok"} @tuyapi/cloud +1ms @tuyapi/cloud Sending parameters: +5ms @tuyapi/cloud { a: 'tuya.m.device.token.create', @tuyapi/cloud deviceId: 'e3rv1lg9tuptv3lorlhq53dxptghd8os9m50lu2xcxpe', @tuyapi/cloud os: 'Linux', @tuyapi/cloud lang: 'en', @tuyapi/cloud v: '1.0', @tuyapi/cloud clientId: 't9d59wv99mnpa89uh3e3', @tuyapi/cloud time: 1535976312, @tuyapi/cloud postData: '{"timeZone":"+01:00"}', @tuyapi/cloud sid: 'az153597j6311240LyPhmv83e80f8eac7ab9dc89419509be2a6857ef', @tuyapi/cloud sign: '9c0a16093af9692f7bc8f3d11f65ba4a' } +1ms @tuyapi/cloud Received response: +192ms @tuyapi/cloud {"t":1535976311740,"success":false,"errorCode":"USER_SESSION_INVALID","status":"error","errorMsg":"Session Expired, please log in again"} @tuyapi/cloud +1ms (node:885) UnhandledPromiseRejectionWarning: #<Object> (node:885) 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:885) [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.
However I still get the same error after trying to connect the powerstrip.
@dickieblack as long as the adapter's enabled it should work. Would you mind capturing packets (from a different computer) during the linking process and sending me the resulting file? I just want to make sure the Pi is correctly broadcasting the setup packets.
@denzel1994 it looks like that app is just a rebranding of Tuya Smart, so your device should be compatible.
I think it's fairly conclusive at this point that it's not a regional issue, because when people in the EU change their region to EU API calls result in USER_SESSION_INVALID
. For the same reason, the timezone parameter is not likely to be at fault either. Therefore, it's probably some issue with devices broadcasting the packets.
Hi, I think you could be right about the broadcasting. I ran WireShark on a PC whilst running the dev.js link wizard and didn’t see any obvious broadcasts. My Raspberry Pi is running OSMC. I did have the wireless adapter disabled, but turning it on a rebooting made no difference.
Actually, I had my packet filter wrong. Now I can see broadcasts from my Pi - UDP source port 63145, dst 30011. If I look at the packets though, the data part is just zeroes. A similar broadcast packet from a Nas device has hex data.
Sounds like it's working.
There is no data in the UDP packets; Tuya instead uses a clever method of encoding the data into packet lengths.
If you enable Wireshark's Len
column you should see a repeating pattern being transmitted.
Ok, I can see the length varies through the broadcasts. And I am sniffing traffic on a wireless adapter on the PC, so the Pi is definitely transmitting the packets in a way that is being broadcast by my router on the wireless network (I had wondered if it was preventing broadcasts from the wired into wireless, but that does not seem to be the case).
My device has finally linked ok using the original link-wizard. The problem was network related. My home network consists of a router plus various APs with different ssids, and I suspect the device wasn't being "seen" from one side of the network to another. Once I ensured that both the Tuya device and the device running the linker were on the exact same network ssid, then it proceeded quite happily.
My network consists of a single router with 2.4G and 5G bands, but the laptop I was linking from was on the 2.4G band. It took maybe a hundred tries or so before the link would succeed.
@chsims1 what do you mean? Would you mind running a few tests and confirming that your computer must be connected to the target SSID for a successful link?
@codehearts during unsuccessful links, did you hear your device click?
@chsims1 I think this might be similar to my issue - I also have multiple APs for the same network. Whilst I can see the broadcast packets on a PC, potentially this is connecting to a different AP than the Tuya devices, or they aren’t all sending the broadcasts.
A relevant note that I should probably put up somewhere: Tuya devices can only connect to a 2.4GHz network. If you have a duel-band network where both networks have the same SSID; that's fine. But if you're trying to link a Tuya device to a 5Ghz network it's not gonna work.
@codetheweb However I can‘t connect my device to the Tuya Smart App.
@codetheweb No clicks when it failed to register. I can't remember if there was a click when it succeeded, either; at some point I was running tuya-cli link
in a while loop and letting it go
@denzel1994 well, that's your issue. If you can't link it with the official app it's not gonna work with tuya-cli
. Is the target network on 2.4Ghz?
Well the powerstrip opens up it’s own Wifi that you have to connect to, then open the Meross App and then pick the local WiFi and enter the password.
The Tuya App works completely different from what I can see. It immediately asks for the password of the WiFi my phone is connected to.
Yeah my local WiFi ist 2,4 and 5 GHz in the same SSID
@denzel1994 usually there's two options for linking. The AP mode, like you explain above, and the UDP method like my package uses. Are you sure there's not a different option for linking? If not, my linking package won't work for your device.
broadcast capture.zip Hi, I have learned a bit more about Wireshark and packet captures and have created one that is just broadcast packets (so its small enough to upload). I can see the repeating pattern UDP packets from 192.168.1.155 - my Raspberry Pi - captured from a PC about 50 cm from the Tuya device. The link never connects. If I then open the Tuya app om my iPhone, i see the same UDP packets, but this time the device registers to the app immediately. I think this means that the infomration is deinfitely being broadcast by the rPi, so if you wan to look at the data, hopefully this will help. Thanks, Richard
Just glanced through your capture and everything looks good @dickieblack. You can see that there's a beginning pattern of Len = [1, 3, 6, 10]
when using my package. Can you confirm that the app uses the same pattern?
I've created the Tuya account and obtained the ID and Key from the site.
When I go to add a device I get the following error. × Device(s) failed to be registered! Error: Timed out wating for device(s) to connect to cloud at Promise (C:\Users\xxxxxx\AppData\Roaming\npm\node_modules\@tuyapi\cli\node_modules\@tuyapi\cloud\index.js:275:12) at
I'm using this smart plug https://www.amazon.com/gp/product/B07CHMDP1G/ref=oh_aui_detailpage_o09_s00?ie=UTF8&psc=1 with the Smart Life app. Running Charles on my iPhone I can confirm it's communicating through the Tuya Cloud. I put the switch in pairing mode but the wizard never finds it. Instantly can add it back to the Smart Life app though.
I use the iOS APP KEY from Tuya for apikey in the wizard and iOS APP Secret from Tuya for apisecret in the wizard. Am I doing something wrong?