codetheweb / tuyapi

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

devid not found on v3.4 Gateway #614

Open mjpoo opened 1 year ago

mjpoo commented 1 year ago

Thanks for adding support for devices running version 3.4

I can connect to my Silvercrest gateway but the data that is returned is devid not found.

The options I'm supplying are:

{
  id: 'abc',
  key: 'xyz',
  version: '3.4'
}
Apollon77 commented 1 year ago

Please run with "DEBUG=Tuyapi* node ..." and provide a full log

mjpoo commented 1 year ago

Sure thing @Apollon77

Here are the logs. It's interesting to see that the payload.version is 3.3 even though I'm feeding it version 3.4

  TuyAPI Finding missing IP undefined or ID abc +0ms
  TuyAPI Received UDP message. +1s
  TuyAPI UDP data: +7ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.999.999',
  TuyAPI     gwId: 'abc',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'xyz',
  TuyAPI     version: '3.3',
  TuyAPI     token: true
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +1ms
  TuyAPI Connecting to 192.168.999.999... +18ms
  TuyAPI Socket connected. +11ms
Connected to Silvercrest
  TuyAPI GET Payload: +4ms
  TuyAPI {
  TuyAPI   gwId: 'abc',
  TuyAPI   devId: 'abc',
  TuyAPI   t: '1669285486',
  TuyAPI   dps: {},
  TuyAPI   uid: 'abc'
  TuyAPI } +0ms
  TuyAPI Received data: XXX +13ms
  TuyAPI Parsed: +2ms
  TuyAPI {
  TuyAPI   payload: 'devid not found',
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 10,
  TuyAPI   sequenceN: 1
  TuyAPI } +2ms
  TuyAPI Received DATA packet +3ms
  TuyAPI data: 10 : "devid not found" +1ms

The log is obfuscations are:

Apollon77 commented 1 year ago

Cna you show your code please?

Apollon77 commented 1 year ago

BTW: In fcat the version tag from the UDP message wins against whatever you initially set in the constructor because UDP is "devicee self declaration".

Do you have the localkey ?

mjpoo commented 1 year ago

Cna you show your code please?

I am using the boilerplate Asynchronous Basic Usage example code and, yes, I'm using the local device key (xyz in my obfuscated example). I am able to get the childIDs from the gateway as a result. I just thought it would be useful to know about this error message being returned in the data.

Apollon77 commented 1 year ago

I guess the error goes away if you use issueGetOnConnect = false in the constructor options. By default 8as per docs) it tries to issue a get after connect biut if this is a gateway then mpst likel ythere are no data to get on the gateway.

mjpoo commented 1 year ago

Yes, if I specify issueGetOnConnect: false then the error goes away but I don't get the child data that I get otherwise (because it is not listening for data because of the flag).

I have no problem but the devid not found message will be confusing to others as it makes it sound as if the gateway could not be found when in fact it is connected and supplying child data.

Apollon77 commented 1 year ago

What you mean with "getting child data"? I do not see anything in the debug log above and the error is the respinse to the GET call

mjpoo commented 1 year ago

What you mean with "getting child data"? I do not see anything in the debug log above and the error is the respinse to the GET call

I was referring to being able to get the data from the child devices using a gateway.get (despite the devid not found message).

Apollon77 commented 1 year ago

The topic is the following: the "default get" can only use the main device id and sets that as gwid and as devId as it is in defaulz.

If you do a manual get you are free to set gwId and devId differently to get the real data - but the "automatic get on connect" can not handle that because it do not have the information. So simply use that flag and do a manual get after connect ith the correct parameters

mjpoo commented 1 year ago

Yes, I get (pardon the pun!) this. The topic of this issue is simply the confusing devid not found message that is returned as data. It did not phase me but others might find it confusing and so either documenting it or handling it for them (as you were previously) may be helpful.

index.js:171

data === 'json obj data unvalid' || data === 'data format error' /* || data === 'devid not found' */