Thanks!! now I understand better how to store variables and I was able to http a response without errors.
Now there is only one thing that is not working. I tried different options, but I'm not being able to form the correct downlink packet.
I need to create a donwlink packet with this format:
{
'{{deviceId}}': {
'downlinkData':{{data}}
}
}
Example: { "234556":{ 'donwlinkData': "dadadadadadadada"}}
But I'm only getting this:
"deviceId":{"downlinkData":"0c01020000000000"}}
instead of deviceId, shoud appear the value of deviceId, like in the example.
Here is the specific code:
var deviceId = flow.get('deviceId')
var payload={
deviceId : {
'downlinkData':data
}}
msg.payload=payload
Thank you so much
Here is the updated node-red flow storing variables:
[{"id":"e9de0deb.075b6","type":"tab","label":"test","disabled":false,"info":""},{"id":"7281aa02.d4a504","type":"function","z":"e9de0deb.075b6","name":"get_device","func":"var deviceId=flow.set('deviceId',msg.payload.device)\nmsg.payload=msg.payload.device\nmsg.topic=\"deviceId\"\nreturn msg;","outputs":1,"noerr":0,"x":395.5,"y":192.5,"wires":[[]]},{"id":"468694fb.2cf1e4","type":"function","z":"e9de0deb.075b6","name":"get_data","func":"msg.payload= msg.payload.data\nmsg.topic=\"data\"\nreturn msg;","outputs":1,"noerr":0,"x":366.5,"y":261.5,"wires":[["af59c9ca.7ab848"]]},{"id":"21e946fb.aad83a","type":"ui_dropdown","z":"e9de0deb.075b6","name":"","label":"Input","place":"Select option","group":"eca7a136.be013","order":0,"width":0,"height":0,"passthru":true,"options":[{"label":"","value":1,"type":"num"},{"label":"","value":2,"type":"num"},{"label":"","value":3,"type":"num"}],"payload":"","topic":"input","x":495.5,"y":114,"wires":[["df39a0c3.85ff9"]]},{"id":"1c1dbaa4.1fc005","type":"http response","z":"e9de0deb.075b6","name":"HTTP Downlink","statusCode":"","headers":{},"x":1091.5,"y":240,"wires":[]},{"id":"af59c9ca.7ab848","type":"function","z":"e9de0deb.075b6","name":"get_packetType","func":"var data=msg.payload;\nvar byte1=parseInt(data.substr(0,2),16);\nvar MASK_BIT_PACKET_TYPE = 0x80;\nvar int_packet_type = ((data & MASK_BIT_PACKET_TYPE) >> 7);\nmsg.payload=int_packet_type;\nmsg.topic=\"packetType\";\nreturn msg","outputs":1,"noerr":0,"x":559.5,"y":261.5,"wires":[["311cf8e0.10bdf"]]},{"id":"16c1ab3a.ec4d25","type":"function","z":"e9de0deb.075b6","name":"response_1","func":"var input = flow.get('input')\nvar deviceId = flow.get('deviceId')\nvar payload_zero=\"00000000000000\"\n\ninput=input.toString(16)\nif (input.length===1)\n{ var str=\"0\";\n input=str.concat(input)}\n\nvar data= input.concat(payload_zero)\n\nvar payload={\n deviceId : {\n\t'downlinkData':data\n }}\nmsg.payload=payload\nreturn msg;","outputs":1,"noerr":0,"x":883.5,"y":215.5,"wires":[["1c1dbaa4.1fc005","27f4edc7.dfe542"]]},{"id":"311cf8e0.10bdf","type":"switch","z":"e9de0deb.075b6","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":727.5,"y":261.5,"wires":[["16c1ab3a.ec4d25"]]},{"id":"80826ed1.78561","type":"http in","z":"e9de0deb.075b6","name":"","url":"/test","method":"post","upload":false,"swaggerDoc":"","x":201.5,"y":259.5,"wires":[["7281aa02.d4a504","468694fb.2cf1e4"]]},{"id":"27f4edc7.dfe542","type":"debug","z":"e9de0deb.075b6","name":"response1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1082.5,"y":201,"wires":[]},{"id":"df39a0c3.85ff9","type":"function","z":"e9de0deb.075b6","name":"Store var","func":"var data=msg.payload;\nvar input=flow.set('input',data)||{}\n","outputs":1,"noerr":0,"x":656.5,"y":113.5,"wires":[[]]},{"id":"eca7a136.be013","type":"ui_group","z":"","name":"Test","tab":"2cc6ac12.156964","disp":true,"width":"24","collapse":false},{"id":"2cc6ac12.156964","type":"ui_tab","z":"","name":"Test","icon":"dashboard"}]