Payload returns nulls
See original GitHub issueDescribe the bug Null payload informations returned
To Reproduce
- 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);
- 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):
- OS: Raspbian Buster
- Node Version v10.21.0
- HW techkin smartplugs https://www.amazon.de/gp/product/B07CDCYLQ6/
Issue Analytics
- State:
- Created 3 years ago
- Comments:30 (22 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
This behavior is now opt-in in v6.0.0.