-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Add support for v3.2 protocol #234
Comments
Please show your code. Mostly this error comes from your code because you do not check errors. |
What I find interesting is I haven't seen this protocol version, would you be able to capture the traffic when controlling the device locally with the app? |
i can see this after mac filter: // Import packages // Helpers /**
*/
|
This doesn't tell me anything, I would need the activity while the device is being controlled by the app, not by |
And exec.js const TuyaDevice = require('tuyapi'); module.exports = function exec(params) {
}; function setState(device, dps, state) { |
I see one of your problems here, you are calling What you have waits for You need to have them called sequentially, as in, |
Have you had any success controlling this device with the example script in the |
with the script in the readme:
thanks |
I can capture the traffic with wireshark, what do you need? |
Control the device with your phone app while it is in local/offline mode, you should see activity over TCP port 6668. |
i can see activity but not on port 6668 |
It's connecting to the cloud, you need to do this offline |
I will try offline with wire shark. With adb:
I had tried: `const TuyAPI = require('tuyapi'); const device = new TuyAPI({
}); let stateHasChanged = false; // Find device on network // Add event listeners device.on('disconnected', () => { device.on('error', error => { device.on('data', data => {
}); // Disconnect after 10 seconds and error:
With anyproy: |
And with device and app connected on computer hotspot, with wireshark, offline: |
Unfortunately, I do not see any activity between your phone and the device in this capture. All I see here are repeated failed attempts to connect to the cloud. Did you successfully control the device with the app while you were recording? |
yes, i had successfully control the device, is it possible? |
@ls819011 If you can control the device locally with the app, not with |
@kueblc Both my Android phone and Tuya switch are in the same wi-fi network but trying to control the switch using Android Smart Life app I see that phone and switch are communicating through the cloud (see "capture-Bridge0-Jul 29 22-27-49.pcapng" in attached archive). No, I didn't use tuyapi earlier. I just purchased my 1st switch and couple of outlets which are also Tuya, at least they all are controlled by Tuya Smart Life app. I'm just in the begining of building my smart home. |
You may be able to force the app to control the device locally if there is no internet connection from the router to the outside world. Code looks OK, though I would advise against using a CPU blocking |
With hostapd and tcpdump, ofline (what option syntax do you need for the command tcpdump?) is it good? |
Yes @Cedopolice you've got it right, now. It does look like the communications are encrypted so I'll need your |
Ok, but, how can i find the localkey? is it the key obtained with anyproxy? |
Yes it is the same key you need to use to be able to control the device, you should already have used it with your |
@kueblc Thanks for your help. I can control switch after adding version to constructor parameters.
but that's does not matter for me. |
I sent the key yesterday. Thanks |
@ls819011 Very happy to hear your issue has been resolved. @Cedopolice I did receive your key, thank you. I ran out of time yesterday but I will try to take a look today. Yes it is AES-ECB-128, which you could learn yourself by looking through the code. I do not have time to explain it, but at a high level I will be taking a look to see if and how the format differs from protocol 3.1 and 3.3 so we can implement 3.2. |
@Cedopolice could you please double check the key that you sent me? I can't seem to get a valid decrypt. If you'd like to try for yourself, this is the data I extracted from your capture:
If you want to test it out in NodeJS, I use this little snippet for testing:
See if you can find the key that produces plaintext from this data. It should be a JSON string. |
Another note, if you use the app to register the device to a new network, it will be issued a new |
TinyTuya recently got 3.2 working, this is what their output looks like. Perhaps their recent changes can be studied: 3 Way Smart Dimmer Switch by Martin Jerry:
|
do ypu have a link? main topic is that I did not saw that many 3.2 versios in the wild or users having issues :-) |
I would start here: jasonacox/tinytuya#168 |
I could also take a shot here. If someone is willing to sende me such a device please contact me at [email protected]. That could simplify things a lot |
I can't send it, but I'm willing to gather whatever info you need from it ... make requests, etc. I have this device, which can't be flashed, and is permanently on 3.2. I pasted some output from it above. |
@Scope666 @cscoppafox nice ... you both have the same devcie ... but no longer possible to order :-( |
Both are the same person, I mistakenly posted from my work account. I deleted and reposted under the correct one. Like I said, I can grab all the info you need from it. Use APIs against it, etc. |
Hm ... ok I checked a bit some other libraries and also added theoretical 3.2 support to my 3.4 branch. What I found is the following: 3.2 is like 3.3 when it comes to encrypted and such, BUT will most likely return "json unvalid" on "get()", so need to use the "refresh" method with the relevant datapoints set to null and such ... this should be handled already by the library already automatically, so "should be all fine" :-) So if someone wants to try -> #606 |
Hi @Apollon77 ... I tried running the 1st listed example code with my device's ID and Key and got this:
|
To make sure: The device is turned on and in the same network where also UDP packages are routed? Plrase try to start again with |
This is from the 3rd listed example that lets you specify an IP:
|
With debug on:
|
Ok, this is what I mentioned but seems "just adifferent error message" then "json obj data unvalid" ... try again github (or try this change locally a0e2048). How it looks then? |
Ok, here's the output after manually editing index.js with your change above:
|
What I'm running:
|
In factthat looks good, or? He was able to query data? Can be optimized because in fact protocol 3.2 should ever return scuh an error so I can remove the first request ... So have fun playing areound more if you like. Try to control something or such |
So it does look like it's connecting and receiving data from the device right? |
Yes exactly. I updated GitHub again to noteven try the "normal get way" when protocol is 3.2 and directly use the alternative way. So if you like play around more with this version ... :-) In fact according to other sources there are other devices that report 3.1 or 3.3 but have a "22 char long deviceid" which should be the same but I'm not 100% sure on that, so we have two calls for these devices for now still. |
Ok, here's the output after your latest changes:
|
Yes, as expected, thank you. Sofor me this would be "kind of fixed" :-) I will bring this together with the protocol 3.4 changes as a PR |
Excellent! If you ever need me to test anything else with the device, please let me know. Ultimate goal is to be able to control the device with LocalTuya in Home Assistant, this is a great first step. |
But is Homeassistant not Python? in any case tinytuya (python lib) already have 3.2 support ... (it ws kind of my reference) |
It is, but LocalTuya mentions tuyapi quite a bit, I figured it might be using parts from it: |
Hm ... ok, but what I saw is that they just had kind of a clone of tinytuya lib in their files ... and yes without 3.2 and 3.4 support ... but tuyapi is not supported ... So in fact they need to update the python stuff |
Bonjour,
J'obtiens cette erreur au demarrage de gladys:
TypeError: Cannot read property '1' of undefined 0|gladys | at _send.then.data (/home/pi/gladys/api/hooks/tuya/node_modules/tuyapi/index.js:123:41) 0|gladys | at <anonymous> 0|gladys | at process._tickDomainCallback (internal/process/next_tick.js:228:7)
et des que j'actionne le device:
0|gladys | (node:18902) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: Cannot read property '1' of undefined 0|gladys | Tuya - Error, undefined device! 0|gladys | Sending 500 ("Server Error") response: 0|gladys | Error: find() timed out. Is the device powered on and the ID or IP correct? 0|gladys | at pTimeout (/home/pi/gladys/api/hooks/tuya/node_modules/tuyapi/index.js:593:19) 0|gladys | at Timeout.setTimeout [as _onTimeout] (/home/pi/gladys/api/hooks/tuya/node_modules/p-timeout/index.js:20:13) 0|gladys | at ontimeout (timers.js:475:11) 0|gladys | at tryOnTimeout (timers.js:310:5) 0|gladys | at Timer.listOnTimeout (timers.js:270:5) 0|gladys | Server Error: 0|gladys |
ligne 123 de tuyapi/index.js:
resolve(data.dps['1']);
J'utilise un smart switch:
SCW NF101
avec wireshark, je recupere:
ip":"192.168.1.xx","gwId":"bfx9268f215ecx78cdkpiv","active":2,"ablilty":0,"encrypt":true,"productKey":"zWxOK04ovOjw0Pxw","version":"3.2"}.B0
Mes identifinats sont de cette forme:
[ { id: 'bfx9268f215ecx78cdkpiv', key: 'b6a93451d8f07ga2' } ]
des idees?
The text was updated successfully, but these errors were encountered: