question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tuya gateway subdevice not found

See original GitHub issue

Describe the bug I have a json file from tuya smart data, which contains all device ID’s and the localKey for the gateway. Tuyapi can connect (and/or discover) the gateway, but can not get data from any subdevice. It may be the fault of my coding…

To Reproduce DEBUG=* node tuya_gw.js (I posted the code below)

Expected behavior I expected to get any available dps data from the given subdevice.

Debug Output

# DEBUG=* node tuya_gw.js
  TuyAPI IP and ID are already both resolved. +0ms
  TuyAPI Connecting to 192.168.0.26... +4ms
  TuyAPI Socket connected. +62ms
Connected to device!
  TuyAPI GET Payload: +3ms
  TuyAPI { gwId: 'bfd62f405900fd4511rabd',
  TuyAPI   devId: 'bfdcbeaf72ae6bfbe7zzoa' } +0ms
  TuyAPI Received data: 000055aa000000010000000a0000001c0000000128794c6c00610d92a29f3b88f40a91210fd902350000aa55 +34ms
  TuyAPI Parsed: +3ms
  TuyAPI { payload: 'devid not found',
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 10,
  TuyAPI   sequenceN: 1 } +0ms
Data from device: devid not found
  TuyAPI Pinging 192.168.0.26 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +30ms
  TuyAPI Parsed: +0ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms
  TuyAPI Pong from 192.168.0.26 +1ms
  TuyAPI Disconnect +5s
  TuyAPI Socket closed: 192.168.0.26 +2ms
Disconnected from device.

# DEBUG=* node tuya_gw.js
  TuyAPI IP and ID are already both resolved. +0ms
  TuyAPI Connecting to 192.168.0.26... +6ms
  TuyAPI Socket connected. +110ms
Connected to device!
  TuyAPI GET Payload: +3ms
  TuyAPI { gwId: 'bfd62f405900fd4511rabd',
  TuyAPI   devId: 'bf88a38b43cae1ca740e09' } +0ms
  TuyAPI Received data: 000055aa000000010000000a0000001c0000000128794c6c00610d92a29f3b88f40a91210fd902350000aa55 +35ms
  TuyAPI Parsed: +4ms
  TuyAPI { payload: 'devid not found',
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 10,
  TuyAPI   sequenceN: 1 } +0ms
Data from device: devid not found
  TuyAPI Pinging 192.168.0.26 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +26ms
  TuyAPI Parsed: +0ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms
  TuyAPI Pong from 192.168.0.26 +1ms
  TuyAPI Disconnect +5s
  TuyAPI Socket closed: 192.168.0.26 +1ms
Disconnected from device.

Screenshots N/A

Desktop (please complete the following information):

  • OS: [ linux (ubuntu)]
  • OS Version [ bionic 4.15.0-43-generic ]
  • Node Version [v8.10.0]

Additional context tuya_gw.js:

const TuyAPI = require('tuyapi');

const device = new TuyAPI({
  ip: '192.168.0.26',
  key: 'xxxx',
  gwID: 'bfd62f405900fd4511rabd',
  id: 'bf88a38b43cae1ca740e09',
  version: 3.3
});

let stateHasChanged = false;

// Find device on network
device.find().then(() => {
  // Connect to device
  device.connect();
});

// Add event listeners
device.on('connected', () => {
  console.log('Connected to device!');
});

device.on('disconnected', () => {
  console.log('Disconnected from device.');
});
device.on('error', error => {
  console.log('Error!', error);
});

device.on('data', data => {
  console.log('Data from device:', data);
});

// Disconnect after 15 seconds
setTimeout(() => { device.disconnect(); }, 15000);

relevant sections from the json file:

{"activeTime":1583615453,"devId":"bf88a38b43cae1ca740e09","displayOrder":0,"dpMaxTime":1583875320214,"dpName":{},"dps":{"1":true,"101":false,"102":true,"103":"1","124":"","125":0,"126":"1","127":16,"128":22,"129":"4","130":"c","131":"B+QDChYW","132":0,"133":true,"134":0,"135":0,"136":true,"137":true,"138":true,"139":true,"2":160,"3":220},"errorCode":0,"iconUrl":"https://...","isShare":false,"key":"bf88a38b43cae1ca740e09","lat":"","lon":"","meshId":"bfd62f405900fd4511rabd","moduleMap":{},"name":"4853_Nappali","nodeId":"505745","productId":"foitasaq52xwyqmt","resptime":0,"runtimeEnv":"prod","timezoneId":"Europe/Budapest","uuid":"bf88a38b43cae1ca740e09","virtual":false},

{"activeTime":1583171103,"devId":"bfdcbeaf72ae6bfbe7zzoa","displayOrder":0,"dpMaxTime":1583875320494,"dpName":{},"dps":{"1":true,"101":false,"102":true,"103":"1","125":0,"126":"1","127":25,"128":25,"129":"4","130":"c","131":"B+QDChYW","132":0,"133":true,"134":0,"135":0,"136":true,"137":true,"138":true,"139":true,"2":250,"3":253},"errorCode":0,"iconUrl":"https://...","isShare":false,"key":"bfdcbeaf72ae6bfbe7zzoa","lat":"","lon":"","meshId":"bfd62f405900fd4511rabd","moduleMap":{},"name":"4947_Lilla","nodeId":"608745","productId":"foitasaq52xwyqmt","resptime":0,"runtimeEnv":"prod","timezoneId":"Europe/Budapest","uuid":"bfdcbeaf72ae6bfbe7zzoa","virtual":false},

{"activeTime":1583170512,"devId":"bfd62f405900fd4511rabd","displayOrder":0,"dpMaxTime":0,"dpName":{},"dps":{},"errorCode":0,"iconUrl":"https://...","isShare":false,"key":"bfd62f405900fd4511rabd","lat":"47.5865865","localKey":"xxxx","lon":"19.0965987",
"moduleMap":{"wifi":
{"bv":"30.04",
"cadv":"1.0.2",
"isOnline":true,
"pv":"2.2",
"verSw":"1.1.6"}
},"name":"Gateway","productId":"tefahiby9c10n9zp","resptime":0,"runtimeEnv":"prod","timezoneId":"Europe/Budapest","uuid":"xxx","virtual":false}],

Tuya smart app shows the very same device ID’s as I see in the json file. Sub devices regulary send broadcast messages:

  TuyAPI Received data: 000055aa00000000000000080000005b00000000332e330000000000015fea0000000156aca002d94a27d5d64756255260ce9e22efac65a96cde6fec763dbcb9b73c759ca31a70b72fb234efe32a4f1aec78db4c7e0ceafe1bcbb2bf327fb2c2fee55b26848c930000aa55 +6s
  TuyAPI Parsed: +1ms
  TuyAPI { payload: { dps: { '131': 'B+QEAxYj' }, cid: '608745', t: 1585946101 },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 8,
  TuyAPI   sequenceN: 0 } +0ms
Data from device: { dps: { '131': 'B+QEAxYj' }, cid: '608745', t: 1585946101 }
  TuyAPI Received data: 000055aa00000000000000080000005b00000000332e330000000000015feb0000000156aca002d94a27d5d64756255260ce9e22efac65a96cde6fec763dbcb9b73c75c4fd2867246c6d871451a9cf29d861c4708fda48f3b814766376e4201f44d4606a05c1a50000aa55 +336ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: { dps: { '131': 'B+QEAxYj' }, cid: '505745', t: 1585946102 },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 8,
  TuyAPI   sequenceN: 0 } +0ms
Data from device: { dps: { '131': 'B+QEAxYj' }, cid: '505745', t: 1585946102 }

Please help me by finding the right code to get dps data or by improving tuyapi to support this kind of device.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
atus42commented, Apr 21, 2020

@danielgiovanni : Unfortunately I was not able to solve it yet. It appears, that even the tuya smart app didn’t communicate to the gateway directly, but through the tuya cloud.

I plan to create an artifical block towards the internet on the AP the devices connected to (Phone, tuya GW), and see if the phone tries to communicate the gateway directly if there is no internet connection to the tuya cloud.

If this didn’t help, I don’t know what else can I do.

0reactions
tasictcommented, Sep 6, 2020

I found something interesting that the same code test with tuya wire zigbee hub and result is different.

/homebridge # DEBUG=* node gateway.js
TuyAPI IP and ID are already both resolved. +0ms TuyAPI Connecting to 10.1.9.28… +6ms TuyAPI Socket connected. +5ms Connected to device! TuyAPI GET Payload: +2ms TuyAPI { TuyAPI gwId: ‘ebdd7925c7531bf4falakg’, TuyAPI devId: ‘ebd2e8be35c5cc00d3nkp9’, TuyAPI t: ‘1599384049’, TuyAPI dps: {}, TuyAPI uid: ‘ebd2e8be35c5cc00d3nkp9’ TuyAPI } +1ms TuyAPI Received data: 000055aa000000010000000a0000001c00000001a4fd046f973e79562bee4dfbd672a9ca03a3f1f40000aa55 +15ms TuyAPI Parsed: +2ms TuyAPI { TuyAPI payload: ‘devid not found’, TuyAPI leftover: false, TuyAPI commandByte: 10, TuyAPI sequenceN: 1 TuyAPI } +1ms Data from device: devid not found TuyAPI Pinging 10.1.9.28 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +5ms TuyAPI Parsed: +0ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +1ms TuyAPI Pong from 10.1.9.28 +0ms TuyAPI Disconnect +5s TuyAPI Socket closed: 10.1.9.28 +2ms Disconnected from device.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does App fail to add devices by Auto Scan? - Tuya.com
Zigbee sub-device: Zigbee gateway needs to be configured. ... If your device is among the above types but still cannot be searched, ...
Read more >
The gateway is next to the device, but the device is still always ...
If the device is still often offline, please check whether the number of sub-devices under the gateway exceeds the upper limit.
Read more >
Connecting to Sub-devices-TuyaOS-Tuya Developer
Open the Smart Life app, select the gateway, and tap Add Sub-device. Then, the gateway will be ready for connecting to a sub-device....
Read more >
Gateway FAQ-TuyaOS-Tuya Developer
Is it possible to link devices under different Zigbee gateways by using the same App account within the same LAN.
Read more >
How to add device in App for Internet connection(Zigbee)?
Find "Gateway Control" on the "Select Device Type" page, find the Gateway (Zigbee) that needs to be added; After successfully adding, you can ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found