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.

Payload returns nulls

See original GitHub issue

Describe the bug Null payload informations returned

To Reproduce

  1. Run async example node asyn.js (https://github.com/codetheweb/tuyapi)
const TuyAPI = require('tuyapi');

const device = new TuyAPI({
  id: 'xxxxxxxxxxxxxxxxxxxx',
  key: 'xxxxxxxxxxxxxxxx'});

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);

  console.log(`Boolean status of default property: ${data.dps['1']}.`);

  // Set default property to opposite
  if (!stateHasChanged) {
    device.set({set: !(data.dps['1'])});

    // Otherwise we'll be stuck in an endless
    // loop of toggling the state.
    stateHasChanged = true;
  }
});

// Disconnect after 10 seconds
setTimeout(() => { device.disconnect(); }, 10000);
  1. Check data from device

Expected behavior Not null values returned

Debug Output Post the output of your program/app/script when run with the DEBUG environment variable set to *. Example: DEBUG=* node test.js. Copy the output and paste it below (in between the code fences):

node async.js
Connected to device!
Error! json obj data unvalid
Data from device: { dps:
   { '1': null,
     '2': null,
     '3': null,
     '101': null,
     '102': null,
     '103': null } }
Boolean status of default property: null.
Data from device: { dps: { '1': true }, t: 1593283963 }
Boolean status of default property: true.
Disconnected from device.

Desktop (please complete the following information):

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
tsightlercommented, Oct 1, 2020

Thanks @codetheweb. Thinking about using SET instead of GET, I wonder if a better option would be to simply implement a fallback to using CONTROL_NEW instead. That seems to be the method that works for these devices. The CONTROL_NEW command seems to have a slightly different schema, basically no gwId: property, otherwise the same and change the command code. That seems to be what other implementations are doing such as:

https://redmine.telecom-bretagne.eu/projects/xaal/repository/entry/code/Python/branches/0.7/devices/protocols/Tuya/xaal/tuya/tuyaclient.py

Unless I’m reading that completely wrong (I’m quite worse at Python vs Javascript, which is perhaps a sad statement) it appears they just try DP_QUERY, if they detect the “json obj data unvalid” message they call fix_buggy_dp_query(), which uses CONTROL_NEW instead.

That’s basically the same as I’m doing in my code, but I’m falling back to a SET with null, since TuyAPI abstacts the commands. I’ll try to hack my local TuyAPI to use the CONTROL_NEW fallback and see if it works.

1reaction
codethewebcommented, Oct 1, 2020

This behavior is now opt-in in v6.0.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Null Payload - infosecgirls - GitBook
In the Payload Options [Null payloads] section, specify the total number of requests ... Start the attack and observe the uid values returned...
Read more >
My api always return null when i call the data - Stack Overflow
You can copy paste run full code below. Step 1: Use bool isLoading to check data is ready or not. Step 2: Use...
Read more >
payload returns null after dataWeave transformation
I am trying to consume soap webservice. i used transofrm message to format the soap request. but payload is always going null .....
Read more >
How can check the null or undefined values - Node-RED Forum
In a function node, you could do something like: if (typeof msg.payload.myVal != 'undefined' && msg.payload.myVal !== null) { return msg; }.
Read more >
transform null to "" in response payload
transform null to "" in response payload ... Concern: Apigee endpoint is pointing to the target endpoint, when we fire a request to...
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