Hi guys,
I would like to get values from 2 nodes which are a text input and a drop down list. When the user press a "Send data" button, a node build a JSON payload to send to a device.
The output format should be like that
{
"command":"testPump",
"pump":"pumpUp",
"value":5
}
Here's my code :
[{"id":"55ce81f8.2b74f8","type":"ui_numeric","z":"b8c69cbb.cbe7b","name":"pumpVolume","label":"Volume (ml)","tooltip":"Volume in ml to dispense","group":"d03b9dd9.59f1e8","order":5,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"pumpVolume","format":"{{value}}","min":0,"max":"50","step":"0.5","x":110,"y":1180,"wires":[["41e1ec7a.1bb2b4"]]},{"id":"4aff2f21.5760b8","type":"ui_dropdown","z":"b8c69cbb.cbe7b","name":"ddlPumps","label":"Pump","tooltip":"Select the peristaltic pump to test","place":"Select option","group":"d03b9dd9.59f1e8","order":0,"width":0,"height":0,"passthru":true,"options":[{"label":"pH up","value":"pumpUp","type":"str"},{"label":"ph down","value":"pumpDown","type":"str"},{"label":"anti-foaming","value":"pumpFoam","type":"str"}],"payload":"","topic":"pump","x":100,"y":1240,"wires":[["41e1ec7a.1bb2b4"]]},{"id":"ccbaec0e.1402b8","type":"debug","z":"b8c69cbb.cbe7b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":1180,"wires":[]},{"id":"f5533ca7.bb5db8","type":"ui_button","z":"b8c69cbb.cbe7b","name":"btnSendPumpData","group":"d03b9dd9.59f1e8","order":2,"width":0,"height":0,"passthru":false,"label":"Send","tooltip":"Send the settings to the pump","color":"","bgcolor":"","icon":"","payload":"1","payloadType":"json","topic":"btnSendPumpData","x":140,"y":1300,"wires":[["41e1ec7a.1bb2b4"]]},{"id":"41e1ec7a.1bb2b4","type":"function","z":"b8c69cbb.cbe7b","name":"","func":"if (msg.topic == \"pump\") {\n context.set(\"pump\", msg.payload);\n return;\n}\n\nif (msg.topic == \"pumpVolume\") {\n context.set(\"pumpVolume\", msg.payload);\n return;\n}\n\nif (msg.topic == \"btnSendPumpData\") {\n msg.topic = \"BIOREACT-2C48\";\n \n msg.payload = \"{\\\"command\\\":\\\"testPump\\\",\" + \n \"pump:\\\"\" + ddlPumps[context.get(\"pump\")] + \"\\\",\" +\n \"value:\" + context.get(\"pumpVolume\") + \"}\";\n \n return msg;\n}\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":1240,"wires":[["ccbaec0e.1402b8"]]},{"id":"d03b9dd9.59f1e8","type":"ui_group","name":"Peristaltics","tab":"823eb67.b157648","disp":true,"width":"6","collapse":false},{"id":"823eb67.b157648","type":"ui_tab","name":"Tests","icon":"dashboard","order":3,"disabled":false,"hidden":false}]
How can I manage to do that?