vinodsr / node-red-contrib-tuya-smart-device

a node-red module for managing tuya smart devices
https://flows.nodered.org/node/node-red-contrib-tuya-smart-device
MIT License
47 stars 15 forks source link

Code data? #27

Closed EngDiego closed 3 years ago

EngDiego commented 3 years ago

I getting strange data from tuya device. Anyone has the same issue?

data: p�@x�J�K�=n���!A2}���2��hzmW

image image

EngDiego commented 3 years ago

Ii tried differents types, but without success!

buff = msg.payload.data

new_buff=buff //new_buff=buff.toString('base64') //new_buff=buff.toString('utf8') //new_buff=buff.toString('hex') //new_buff=buff.toString('utf16le')

node.status({"text" : new_buff}); msg.payload = new_buff return msg;

image

msillano commented 3 years ago

I fond a similar behavior: this is the device (sirene) response to a change (type) done by smartLive:

data: "3.34��o0a�1� ���~q����Q�S↵����7nKC�K�����→����O��� ��6EU: ̤sG�x��tpa" deviceId: "42027807d8bfc0c5831e" deviceName: "Sirena" excode: "332e33000000000000003400000001fdfd6f300861fd31fd20fdfdfd7e161610180671fdfdfdfd0451fd530afdfdfdfd1b376e4b43fd4b60fd6002fdfdfdfdfd09fdfdfdfd4ffdfd1efd20fdfd3645553a0c247347fd78fdfd747061" The field "excode" is added by code: const buf = Buffer.from(msg.payload.data, 'ascii'); msg.payload.excode =buf.toString("hex");

Very strange is the presence of many 0x00 bytes in a JSON value (not visible in the string !) The same device, if I send a tentative {"operation":"SET", "dps":1, "set":1}:

data: "8e�cH[��*����QPjp|a�ttDk{��" deviceId: "42027807d8bfc0c5831e" deviceName: "Sirena" excode: "183865fd63485bfdfd2afdfdfdfd51506a707c61fd0e747410441e6b7bfdfd15"

Any idea?

Best regards, m.s.

vinodsr commented 3 years ago

I suspect it is due to a newer firmware in the device. Did you update the firmware using the parent app ?

msillano commented 3 years ago

I don't remember exactly if tuya updates the firmware of the siren device, I think yes, but that was some time ago, pairing many devices. On smartLife i see:

    Modulo principale V3.1.4
    Modulo MCU: V1.0.0  

Any command send by smartLife (I'm in the phase of sending commands to explore existing dps) give some like this: on console:

4 Jan 14:20:19 - [info] [tuya-smart-device:c6a8cb8d.9198b8] Data from device: "3.3\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0002\u0000\u0000\u0000\u0001��o0\ba�1� ���~\u0016\u0016\u0010\u0018\u0006q����\u0004Q�S\n���\u0002)A�\u0000 \u001c.\b��l`�7�\u0005��~䪪�6p\rm�E�\u0017"

on debug pad, filtered by mine nodes:

4 Jan 14:20:19 - [warn] [function:*OUT data process] ERROR from 'Sirena d'allarme': not JSON data but HEX:332e33000000000000000200000001efbfbdefbfbd6f300861efbfbd31efbfbd20efbfbdefbfbdefbfbd7e161610180671efbfbdefbfbdefbfbdefbfbd0451efbfbd530aefbfbdefbfbdefbfbd022941efbfbd00201c2e08efbfbdefbfbd6c60efbfbd37efbfbd05efbfbdefbfbd7ee4aaaaefbfbd36700d6defbfbd45efbfbd17  ('3.3          ��oa�1� ���~q����Q�S
m�E�')  ��l`�7���~䪪�6p

And so for ANY command: it is executed (smartlife works very well) but that is the result using tuya-smart-device 2.0.0. The starting "3.3" looks like a version...

ERROR from 'Sirena d'allarme': not JSON data but HEX:332e33000000000000000300000001efbfbdefbfbd6f300861efbfbd31efbfbd20efbfbdefbfbdefbfbd7e161610180671efbfbdefbfbdefbfbdefbfbd0451efbfbd530aefbfbdefbfbdefbfbd0505efbfbd36c38fefbfbd277008efbfbd4930efbfbdefbfbd6cefbfbd315946e9a39c44efbfbdefbfbd457c5a5857efbfbd3645553a0ccca47347efbfbd78efbfbdefbfbd747061  ('3.3��o0a�1� ���~q����Q�S
����6Ï�'p�I0��l�1YF飜D��E|ZXW�6EU:̤sG�x��tpa')

This issue has for me low priority: I have a workaround to exchange data with any devices not caught by tuyapi and tuya-smart-device node (but limited to BOOL and ENUM. don't sends/receives INT like sensor values).

Thanks and best regards m.s.

EngDiego commented 3 years ago

I found a solution that is not pretty but it works. I collect some samples of each state of the device and identify the position of the character in the string that matches what was expected. Then for a function I use "if condition" for a msg.payload true or false.

image

image

image

[{"id":"5913353a.5f3fec","type":"ui_led","z":"c193e48a.aca048","group":"e412097d.839e88","order":1,"width":0,"height":0,"label":"Luz Natal 1","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"gray","value":"false","valueType":"bool"},{"color":"green","value":"true","valueType":"bool"}],"allowColorForValueInMessage":false,"name":"Luz Natal 1","x":470,"y":460,"wires":[]},{"id":"b448f0ee.3cca3","type":"tuya-smart-device","z":"c193e48a.aca048","deviceName":"Luz Natal 1","deviceId":"xxxxxxxxxxxxx","deviceKey":"yyyyyyyyyyyyyyyy","x":150,"y":460,"wires":[["1570268c.bfc569"]]},{"id":"1570268c.bfc569","type":"function","z":"c193e48a.aca048","name":"","func":"status = String(msg.payload.data)\n\n//Precisa descobrir a posição do caractere na string\nstatus1 = status.substr(16, 1)\nnode.status(status1);\n if(status1==\"Y\")\n {\n msg.payload = true\n }\n else\n { \n msg.payload = false\n }\nreturn msg\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":300,"y":460,"wires":[["5913353a.5f3fec"]]},{"id":"e412097d.839e88","type":"ui_group","name":"Col1","tab":"250de740.57ee78","order":1,"disp":false,"width":"3","collapse":false},{"id":"250de740.57ee78","type":"ui_tab","name":"Dashboard Home Indicator","icon":"home","order":1,"disabled":false,"hidden":false}]

msillano commented 3 years ago

A clever solution, to be taken into consideration. Thanks, added to the group of possible solutions. Best regards m.s.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 3 years ago

Auto closing the issue