Skip to content
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

json obj data unvalid #14

Closed
AymanFadda opened this issue Sep 27, 2020 · 7 comments
Closed

json obj data unvalid #14

AymanFadda opened this issue Sep 27, 2020 · 7 comments
Assignees
Labels
good first issue Good for newcomers
Milestone

Comments

@AymanFadda
Copy link

Hi, I'm trying to get the power, current and voltage data from a Tuya device. Following your example, the node workds perfectly to switch on/off the Tuya smart plug. When I try to use GET, I receive the error "json obj data unvalid".
I tried in node-red to write:
msg.payload ={
operation : "GET",
dsp: 19
}
return msg;

I tried also:
msg.payload ={
operation : "GET",
schema: true
}
return msg;

But I continue to get the same error with this answer from the device:
{"payload":{"data":{"dps":{"1":null,"2":null,"3":null,"101":null,"102":null,"103":null}},"deviceId":"[my deivce ID]","deviceName":"[My device name]"},"_msgid":"47701b1b.667bb4"}

Would you please help with some GET examples?

Thank you

@vinodsr
Copy link
Owner

vinodsr commented Sep 28, 2020

This is a known issue with some devices to query the exact status codetheweb/tuyapi#77

But you will be able to get the events associated with the device.

I am trying to find some alternatives.

Hope the set command is working fine :)

@vinodsr vinodsr added bug Something isn't working good first issue Good for newcomers labels Sep 28, 2020
@vinodsr vinodsr self-assigned this Sep 28, 2020
@vinodsr vinodsr added this to the 1.2 milestone Sep 28, 2020
@vinodsr
Copy link
Owner

vinodsr commented Sep 29, 2020

@AymanFadda Can you please confirm the fimware version of the device ?

Got to Tuya app-> choose the device -> edit -> Select the "Check for firmware update at the bottom"

@vinodsr vinodsr removed the bug Something isn't working label Sep 29, 2020
@AymanFadda
Copy link
Author

Hi. The firmware version is 1.4.2 both for main module and MCU module.
Thanks

@vinodsr
Copy link
Owner

vinodsr commented Oct 2, 2020

This is a know issue with the tuya library on some devices.

More details about the issue can be found at codetheweb/tuyapi#338

Once it is fixed, we can bring the changes here.

Meanwhile i found a trick to resolve this issue partially .

Make the IP of the device static, and block all TCP/UDP connections above 6670 port from this IP. ( You router should support port blocking) . This prevents the cloud communication of the device. the json unvalid error has to do some thing with the communication with the tuya cloud api. so we are blocking it. Now only using the node we will be able to control the device. The app has no use now. You can disable to the port blocking and re connect the device to configure it via the app.

Once getting the response as null , hit a get request for dps 11( in my case it is the timer ) and value as 0. subsequent get calls wont give the json error. But it will return only the status of the 11 dps until some one issues a power on / off command.

Here is the flow for your reference

[{"id":"b3fe7bd8.137bb8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"e193ccfe.40b18","type":"tuya-smart-device","z":"b3fe7bd8.137bb8","deviceName":"Monitor Plug","deviceId":"ID","deviceKey":"VAL","x":810,"y":260,"wires":[["eeb76561.97b738","fb0c7d92.cda94"]]},{"id":"bfe7b1db.54784","type":"function","z":"b3fe7bd8.137bb8","name":"","func":"msg.payload ={\n dps : 1,\n set : msg.payload\n}\n\n/*\n\n */\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":440,"y":180,"wires":[["e193ccfe.40b18"]]},{"id":"eeb76561.97b738","type":"debug","z":"b3fe7bd8.137bb8","name":"Monitor Log","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1270,"y":160,"wires":[]},{"id":"d80648b8.1f5648","type":"inject","z":"b3fe7bd8.137bb8","name":"Get Schema","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"operation\":\"GET\",\"schema\":true}","payloadType":"json","x":250,"y":240,"wires":[["e193ccfe.40b18"]]},{"id":"e018fb88.6488c8","type":"function","z":"b3fe7bd8.137bb8","name":"","func":"msg.payload ={\n dps : 11,\n set : 0\n}\n\nnode.error(\"re sending the data\")\n/*\n\n */\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":560,"y":320,"wires":[["e193ccfe.40b18"]]},{"id":"fb0c7d92.cda94","type":"function","z":"b3fe7bd8.137bb8","name":"","func":"\nlet valueCount = Object.values(msg.payload.data.dps).filter(a=>a!=null).length;\nif(valueCount > 0) {\n // its fine\n msg.payload=false;\n} else {\n msg.payload=true;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":980,"y":320,"wires":[["57e44bad.d254e4"]]},{"id":"f8470da2.7efb8","type":"inject","z":"b3fe7bd8.137bb8","name":"Turn On","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":240,"y":160,"wires":[["bfe7b1db.54784"]]},{"id":"bb2fc171.0e31f","type":"inject","z":"b3fe7bd8.137bb8","name":"Turn Off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":240,"y":200,"wires":[["bfe7b1db.54784"]]},{"id":"57e44bad.d254e4","type":"switch","z":"b3fe7bd8.137bb8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":770,"y":360,"wires":[["e018fb88.6488c8"]]}]

Closing the issue as this is not a bug with this library

@juampe
Copy link

juampe commented Nov 9, 2020

I see mispelling of the dps parameter in your code.

dsp: 19

@AymanFadda
Copy link
Author

I see mispelling of the dps parameter in your code.

dsp: 19

Thank you Juampe. with both dsp or dps it's not working. As vinodsr said, it must be a problem in the API of Tuya.

@vinodsr
Copy link
Owner

vinodsr commented Nov 10, 2020

I see mispelling of the dps parameter in your code.

dsp: 19
;
Lets wait for the release of tuyapi with the fix. Once it is ready I will patch this node. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants