Hello!
I am making a project that sends information to a file using a form node to get the inputs, wich in this case is some values of voltage. Later, i want to simulate the reception of other values, current values to be specific, using for now a inject node (i have to use a serial COM), and save them in the same file.
The file in the end must have the inicial inputs in each row (Voltage and Value), then, the index (which i get using (parts.index +1) in change node) plus the inputs plus the reveived values, in 3 columns.
I have already done the folowing, but my problem is to understand how to make the inputs a global variable to use in the end when i send all the information to the file.
[{"id":"4d5f22d9.f913ec","type":"ui_form","z":"62df8887.e2aba8","name":"Send voltages values","label":"","group":"b7e0c0ec.6c043","order":4,"width":0,"height":0,"options":[{"label":"Voltage (V):","value":"Voltage1","type":"number","required":true,"rows":null},{"label":"Voltage (V):","value":"Voltage2","type":"number","required":true,"rows":null},{"label":"Voltage (V):","value":"Voltage3","type":"number","required":true,"rows":null},{"label":"Voltage (V):","value":"Voltage4","type":"number","required":true,"rows":null}],"formValue":{"Voltage1":"","Voltage2":"","Voltage3":"","Voltage4":""},"payload":"","submit":"Start","cancel":"Stop","topic":"topic","topicType":"msg","splitLayout":"","x":140,"y":80,"wires":[["9eee3b3d.ebd678"]]},{"id":"9eee3b3d.ebd678","type":"change","z":"62df8887.e2aba8","name":"","rules":[{"t":"set","p":"numeric","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":140,"y":160,"wires":[["cda0b5d6.406dc8","7f60c615.9446d8"]]},{"id":"b8499ad7.ef1dd8","type":"debug","z":"62df8887.e2aba8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1150,"y":340,"wires":[]},{"id":"cda0b5d6.406dc8","type":"debug","z":"62df8887.e2aba8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":150,"y":220,"wires":[]},{"id":"7f60c615.9446d8","type":"split","z":"62df8887.e2aba8","name":"","splt":"\\n","spltType":"str","arraySplt":"2","arraySpltType":"len","stream":false,"addname":"","x":330,"y":160,"wires":[["5eb9c9d9.950cf8"]]},{"id":"5eb9c9d9.950cf8","type":"change","z":"62df8887.e2aba8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"\"Voltage\" & \" \" & payload","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":160,"wires":[["a4ba5b0b.21ce18"]]},{"id":"a4ba5b0b.21ce18","type":"join","z":"62df8887.e2aba8","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":710,"y":160,"wires":[["73c9cf3d.b9b01"]]},{"id":"2ad7ffa.cbf5e","type":"template","z":"62df8887.e2aba8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"55\n65\n75\n85","x":300,"y":360,"wires":[["e9cf4f03.c99cf","3b2f3445.4a02cc"]]},{"id":"e9cf4f03.c99cf","type":"split","z":"62df8887.e2aba8","name":"","splt":"\\n","spltType":"str","arraySplt":"1","arraySpltType":"len","stream":false,"addname":"","x":110,"y":440,"wires":[["4e01174b.78a358"]]},{"id":"4e01174b.78a358","type":"change","z":"62df8887.e2aba8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"(parts.index +1) & \" \" & payload ","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":440,"wires":[["bf436231.5b8fb"]]},{"id":"bf436231.5b8fb","type":"join","z":"62df8887.e2aba8","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":570,"y":440,"wires":[["73c9cf3d.b9b01"]]},{"id":"73c9cf3d.b9b01","type":"file","z":"62df8887.e2aba8","name":"","filename":"Desktop\\Files\\teste1.txt","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":790,"y":340,"wires":[["b8499ad7.ef1dd8","be686752.b3e738"]]},{"id":"22a3448.fcef5bc","type":"inject","z":"62df8887.e2aba8","name":"Receive Current","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"","payloadType":"date","x":140,"y":360,"wires":[["2ad7ffa.cbf5e"]]},{"id":"3b2f3445.4a02cc","type":"debug","z":"62df8887.e2aba8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":490,"y":360,"wires":[]},{"id":"25f2fadf.7b0c76","type":"comment","z":"62df8887.e2aba8","name":"Blank line + header","info":"","x":390,"y":240,"wires":[]},{"id":"d8fb2f57.72e29","type":"inject","z":"62df8887.e2aba8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"\" \"","payloadType":"jsonata","x":570,"y":240,"wires":[["73c9cf3d.b9b01"]]},{"id":"582ed720.205bd8","type":"inject","z":"62df8887.e2aba8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Index Current Voltage","payloadType":"str","x":520,"y":280,"wires":[["73c9cf3d.b9b01"]]},{"id":"6de3c7e8.314528","type":"function","z":"62df8887.e2aba8","name":"Global context","func":"var V = global.get(\"voltage\");\nglobal.set(\"voltage\", msg.payload);\nreturn msg;\n\n//it will store the msg.payload, received on the input of the node\n//to a global variable, that can be used anytime/flow\n\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":980,"y":140,"wires":[[]]},{"id":"f5173a9a.7a1b18","type":"change","z":"62df8887.e2aba8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Voltage","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":980,"y":180,"wires":[[]]},{"id":"be686752.b3e738","type":"function","z":"62df8887.e2aba8","name":"","func":"var i = msg.payload.col1;\nglobal.set(\"$col1\",i);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":920,"y":420,"wires":[["b8499ad7.ef1dd8"]]},{"id":"f6aa8ca5.6e7fc","type":"comment","z":"62df8887.e2aba8","name":"Options to get global variable","info":"","x":980,"y":100,"wires":[]},{"id":"b7e0c0ec.6c043","type":"ui_group","name":"Parameter","tab":"30246011.589d1","order":1,"disp":true,"width":8,"collapse":false},{"id":"30246011.589d1","type":"ui_tab","name":"Simulation","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
The inputs and the file obtained are:
I have tried to use a function in the beginning to define the global variable or even a change node (with set mode to make msg.payload to global):
var V = global.get("voltage");
global.set("voltage", msg.payload);
return msg;
And still, i don´t understand waht i am doing wrong. Other problem is when i save the file in csv format, all the values are in column 1. How can i distribute them in different columns?
Sorry for the long post, i hope someone can help in any form. Thank you!