Unable to save and retrieve value from DropDownList

Hey guys,

I'm new to Node-Red. I can't figure out what I'm doing wrong. I'm trying to save a value in the flow from a drop down node and read the value from the function node. I always get "NOT SELECTED" in the function node.

[{"id":"3af75896.27e58","type":"ui_dropdown","z":"b8c69cbb.cbe7b","name":"ddlPumps","label":"Pump","tooltip":"Select the peristaltic pump to test","place":"Select option","group":"d03b9dd9.59f1e8","order":1,"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":1480,"wires":[["365f782d.bd3af"]]},{"id":"8661e099.ddaa1","type":"debug","z":"b8c69cbb.cbe7b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":1260,"wires":[]},{"id":"115e876f.20c7c1","type":"ui_button","z":"b8c69cbb.cbe7b","name":"btnSendPumpData","group":"d03b9dd9.59f1e8","order":3,"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":130,"y":1260,"wires":[["3e42d2f7.fb706e"]]},{"id":"3e42d2f7.fb706e","type":"function","z":"b8c69cbb.cbe7b","name":"convTestPumpData","func":"var pump = flow.get(\"pump\") || \"DEFAULT VALUE\"; \nvar volume = flow.get(\"testVolume\") || 0;\nvar bioreactor = flow.get(\"testDevice\") || \"NOT SELECTED\";\n\nmsg.topic = bioreactor;\nmsg.payload = {\n    \"command\": \"testPump\",\n    \"pump\": pump,\n    \"value\": volume\n}\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":1260,"wires":[["8661e099.ddaa1","7db76ac1.673d94"]]},{"id":"f6f54579.8b00d8","type":"change","z":"b8c69cbb.cbe7b","name":"Save Value","rules":[{"t":"set","p":"testVolume","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":1420,"wires":[[]]},{"id":"365f782d.bd3af","type":"change","z":"b8c69cbb.cbe7b","name":"Save Value","rules":[{"t":"set","p":"pump","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":1480,"wires":[[]]},{"id":"58d08b5.8f13b74","type":"ui_text_input","z":"b8c69cbb.cbe7b","name":"volume","label":"Volume (ml)","tooltip":"Set the volume to test","group":"d03b9dd9.59f1e8","order":2,"width":0,"height":0,"passthru":true,"mode":"number","delay":300,"topic":"pumpVolume","x":100,"y":1420,"wires":[["f6f54579.8b00d8"]]},{"id":"ff02c3d1.d46c4","type":"ui_dropdown","z":"b8c69cbb.cbe7b","name":"ddlBioreactor","label":"Bioreactor ID","tooltip":"Select the bioreactor to test","place":"Select option","group":"8490db0d.eb778","order":1,"width":0,"height":0,"passthru":true,"options":[{"label":"2C48","value":"BIOREACT-2C48","type":"str"}],"payload":"","topic":"testDevice","x":120,"y":1360,"wires":[["c6e134b6.cd7128"]]},{"id":"c6e134b6.cd7128","type":"change","z":"b8c69cbb.cbe7b","name":"saveTestDevice","rules":[{"t":"set","p":"testDevice","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":1360,"wires":[[]]},{"id":"7db76ac1.673d94","type":"mqtt out","z":"b8c69cbb.cbe7b","name":"mqtt_sendCommand","topic":"","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"e31a38f2.533f1","x":920,"y":840,"wires":[]},{"id":"d03b9dd9.59f1e8","type":"ui_group","name":"Peristaltics","tab":"823eb67.b157648","order":2,"disp":true,"width":"6","collapse":false},{"id":"8490db0d.eb778","type":"ui_group","name":"Device","tab":"823eb67.b157648","order":1,"disp":true,"width":"6","collapse":false},{"id":"e31a38f2.533f1","type":"mqtt-broker","name":"MosquittoBroker","broker":"localhost","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"823eb67.b157648","type":"ui_tab","name":"Tests","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

Can someone tell me what I'm doing wrong?

The "NOT SELECTED" is default value for bioreactor.

var bioreactor = flow.get("testDevice") || "NOT SELECTED";

If you don't select it from first dropdown, it is the value what is put to the outgoing msg.topic
For me it works as expected.

It didn't work well with a single value. Now I added a "NOT SELECTED" in the ddl and it seems to work.

Thanks

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.