Device(s) Failed to be registered!
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?
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: '[email protected]', 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":"[email protected]","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":"[email protected]","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":"[email protected]","snsNickname":"","improveCompanyInfo":false,"username":"[email protected]"},"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":"[email protected]","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.