Simple task but very difficult

I am completely new to node-RED, evaluation if we could use it, but finding a very simple task too frustrating for me and do not find any good examples.

The task is, 4 sliders and getting them into function node so that their values can then be further processed and result with some other data passed out as array to be send to serial port.

There is just one input on the function??

Changing any of the slider will cause new output of the function. The function should all the time know the position of all the sliders.

I would be happy finding an example that takes multiple sliders as input to a function, sums them up if any of them is moved and displays the result. That is not what I am trying to do but would show how to get multiple sliders in to the function and access them in the function.

Link slider1 to its own change node. In the change node, set flow.slider1 to msg.payload.

Repeat for slider2, slider3 and slider4

Then use a button and link that to a function where you can get all 4 values from flow at once & put the values into and array (or buffer). Then link the function to a serial node.

The code to get something from flow is flow.get("slider1");

Alternatively, use the join node. See this article in the cookbook for an example of how to join messages into one object.

Here is an example using the join node. The injects are for testing and generate a random number, Have a play hope it helps.

[{"id":"c80bbf28.a5eed8","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$round($random()*9)","payloadType":"jsonata","x":90,"y":3660,"wires":[["755df129.aebf08"]]},{"id":"755df129.aebf08","type":"ui_slider","z":"5a245aa1.510164","name":"","label":"1000","tooltip":"","group":"8b5cde76.edd58","order":4,"width":0,"height":0,"passthru":true,"outs":"end","topic":"thousand","topicType":"str","min":0,"max":"10","step":1,"x":230,"y":3680,"wires":[["c900bea7.7f1108"]]},{"id":"c900bea7.7f1108","type":"join","z":"5a245aa1.510164","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":400,"y":3740,"wires":[["46e3c0d7.c48b5"]]},{"id":"8aea7870.00324","type":"ui_slider","z":"5a245aa1.510164","name":"","label":"1","tooltip":"","group":"8b5cde76.edd58","order":4,"width":0,"height":0,"passthru":true,"outs":"end","topic":"unit","topicType":"str","min":0,"max":10,"step":1,"x":230,"y":3860,"wires":[["c900bea7.7f1108"]]},{"id":"2f0e72cd.eba9b6","type":"ui_slider","z":"5a245aa1.510164","name":"","label":"10","tooltip":"","group":"8b5cde76.edd58","order":4,"width":0,"height":0,"passthru":true,"outs":"end","topic":"ten","topicType":"str","min":0,"max":10,"step":1,"x":230,"y":3800,"wires":[["c900bea7.7f1108"]]},{"id":"4c944021.62a4a","type":"ui_slider","z":"5a245aa1.510164","name":"","label":"100","tooltip":"","group":"8b5cde76.edd58","order":4,"width":0,"height":0,"passthru":true,"outs":"end","topic":"hundred","topicType":"str","min":0,"max":10,"step":1,"x":230,"y":3740,"wires":[["c900bea7.7f1108"]]},{"id":"46e3c0d7.c48b5","type":"function","z":"5a245aa1.510164","name":"","func":"let thousands = (msg.payload.thousand || 0) * 1000,\nhundreds = (msg.payload.hundred || 0) * 100,\ntens = (msg.payload.ten || 0) * 10,\nunits = msg.payload.unit || 0;\nmsg.payload.total = thousands + hundreds + tens + units;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":3800,"wires":[["8fb379e3.1e2938","64a84df4.8ed5cc"]]},{"id":"9a2d6f08.539b5","type":"inject","z":"5a245aa1.510164","name":"reset","props":[{"p":"reset","v":"","vt":"date"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":3940,"wires":[["c900bea7.7f1108"]]},{"id":"f4ec0a9.aefdcf8","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$round($random()*9)","payloadType":"jsonata","x":90,"y":3880,"wires":[["8aea7870.00324"]]},{"id":"34423f11.ece648","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$round($random()*9)","payloadType":"jsonata","x":90,"y":3800,"wires":[["2f0e72cd.eba9b6"]]},{"id":"33e2c29b.3e992e","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$round($random()*9)","payloadType":"jsonata","x":90,"y":3740,"wires":[["4c944021.62a4a"]]},{"id":"8fb379e3.1e2938","type":"debug","z":"5a245aa1.510164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":600,"y":3740,"wires":[]},{"id":"64a84df4.8ed5cc","type":"ui_text","z":"5a245aa1.510164","group":"8b5cde76.edd58","order":8,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload.total}}","layout":"row-spread","x":580,"y":3880,"wires":[]},{"id":"8b5cde76.edd58","type":"ui_group","name":"","tab":"8f03e639.85956","order":1,"disp":true,"width":"6","collapse":false},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Thanks a lot E1cid, that is exactly what I needed.

Still a question about the sliders, is there a way to configure individual colour for each of them?

There are a few threads on the forum eg...

the Join works great to Join one or more sliders to function and access the values in function, but have now case where I need just 1 slider into function, but after an hour trying the frustration is too big and feel so stupid. I just do not sucseed on that or find answer and have tried so many things.

There must be a way to get a single slider into a function without the Join? This is relevant as there will be many sliders and functions, just one slider per function.

This is what I have now, this works, but there will be many more sliders that update fast. I woull like to connect the sliders directly to LVZ ID functions to reduse data flows and wiring.

[{"id":"b09033c8.c730f8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"5a75194f.6c0a3","type":"ui_slider","z":"b09033c8.c730f8","name":"Focus","label":"Focus","tooltip":"","group":"3014c2c4.1707ee","order":0,"width":0,"height":0,"passthru":true,"outs":"all","topic":"focus","topicType":"str","min":0,"max":"2048","step":1,"x":290,"y":140,"wires":[["fced7983.2b89b8"]]},{"id":"fced7983.2b89b8","type":"join","z":"b09033c8.c730f8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":520,"y":200,"wires":[["3fdd9590.152cd2","303bbf3.ced62c"]]},{"id":"1f64652a.080f73","type":"function","z":"b09033c8.c730f8","name":"Build LVZ type 10 message","func":"\n\n//Build LVZ header\nvar Camera   = msg.payload.camera||1;\nvar Type     = 10;//BMD v1.5 type messages\n\nvar Counter  = context.get('Counter')||0;\nif (Counter >= 127) {Counter = 0;} else {Counter++;}\ncontext.set('Counter',Counter);\n\nvar LVZheader   = [0xFF, 0xFF, 0xFF,Camera ,Type ,Counter ];\n\n//the LVZ message data\nvar LVZ_ID_data  = msg.payload.LVZ_ID;\n\n//combine header and data\nvar LVZdata  = LVZheader.concat(LVZ_ID_data);\n\n//calculate checksum\nvar i;\nvar Cksm = 0;\nfor (i = 3; i < LVZdata.length; i++) { Cksm += LVZdata[i]; }\nvar LVZchecksum = [0x00, (Cksm & 0xFF), ((Cksm >> 8) & 0xFF)];\n\n//the complete LVZ message\nvar LVZmsg    = LVZdata.concat(LVZchecksum);\n\nmsg.payload = Buffer.from(LVZmsg);\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":900,"y":240,"wires":[["5fcda6fc.222ae8","4764da54.6ab0cc"]]},{"id":"4764da54.6ab0cc","type":"ui_text","z":"b09033c8.c730f8","group":"16848fb.06e187","order":0,"width":0,"height":0,"name":"LVZ out","label":"","format":"{{msg.payload}}","layout":"row-spread","x":1140,"y":320,"wires":[]},{"id":"7434077.1fbfc78","type":"ui_numeric","z":"b09033c8.c730f8","name":"Camera Number","label":"Camera Number","tooltip":"","group":"3014c2c4.1707ee","order":1,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"camera","topicType":"str","format":"{{value}}","min":0,"max":"255","step":1,"x":320,"y":60,"wires":[["fced7983.2b89b8"]]},{"id":"5fcda6fc.222ae8","type":"serial out","z":"b09033c8.c730f8","name":"LVZ Control","serial":"e3e2bb7b.7339f8","x":1150,"y":240,"wires":[]},{"id":"8b7649c3.3c2a","type":"serial in","z":"b09033c8.c730f8","name":"","serial":"e3e2bb7b.7339f8","x":680,"y":660,"wires":[[]]},{"id":"52b905e8.9049b4","type":"ui_slider","z":"b09033c8.c730f8","name":"Gain","label":"Gain.","tooltip":"","group":"3014c2c4.1707ee","order":0,"width":0,"height":0,"passthru":true,"outs":"all","topic":"gain","topicType":"str","min":0,"max":"16","step":1,"x":290,"y":280,"wires":[["fced7983.2b89b8"]]},{"id":"303bbf3.ced62c","type":"function","z":"b09033c8.c730f8","name":"LVZ ID 1 Focus","func":"\n\n//the LVZ message data\nvar DataIn  = msg.payload.focus;\nvar DataH   = ((DataIn >> 8) & 0xFF)||0;\nvar DataL   = (DataIn & 0xFF||0);\nvar LVZ_ID1 = [1, DataL, DataH];\n\nmsg.payload.LVZ_ID = LVZ_ID1;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":680,"y":80,"wires":[["1f64652a.080f73"]]},{"id":"3fdd9590.152cd2","type":"function","z":"b09033c8.c730f8","name":"LVZ ID 31 Gain","func":"\n\n//the LVZ message data\nvar DataH   = ((msg.payload.gain >> 8) & 0xFF)||0;\nvar DataL   = (msg.payload.gain & 0xFF||0);\nvar LVZ_ID1  = [31, DataL, DataH];\n\nmsg.payload.LVZ_ID = LVZ_ID1;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":680,"y":260,"wires":[["1f64652a.080f73"]]},{"id":"3014c2c4.1707ee","type":"ui_group","name":"LVZ control","tab":"f6783245.9294e8","order":1,"disp":true,"width":"6","collapse":false},{"id":"16848fb.06e187","type":"ui_group","name":"LVZ out","tab":"f6783245.9294e8","order":2,"disp":true,"width":"6","collapse":false},{"id":"e3e2bb7b.7339f8","type":"serial-port","z":"b09033c8.c730f8","serialport":"/dev/tty.usbmodem43317101","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"0","bin":"bin","out":"time","addchar":"","responsetimeout":"10000"},{"id":"f6783245.9294e8","type":"ui_tab","name":"Demo","icon":"dashboard","disabled":false,"hidden":false}]

You need to edit your post as it won't be importable.

In order to make code more readable and importable it is important to surround your code with three backticks
```
like this
```

You can edit and correct your post by clicking the pencil icon.

See this post for more details - How to share code or flow json

The built-in help for slider says...

If you add debug nodes to the output of things (sliders) you would see this
image

So in your function...

//the LVZ message data

// CHANGE THIS ...
//var DataIn  = msg.payload.focus; 

// TO THIS ...
var DataIn  = msg.payload; 

var DataH   = ((DataIn >> 8) & 0xFF)||0;
var DataL   = (DataIn & 0xFF||0);
var LVZ_ID1 = [1, DataL, DataH];

//Depending on where you want the result, change the following
// msg.payload.LVZ_ID = LVZ_ID1;
//to something like this....
msg.payload= LVZ_ID1;
return msg;

Forgive me for saying so, but this is very very base node-red knowledge. If you are new to node-red, I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Thanks Steve,

This was one of the first things I tried var DataIn = msg.payload; but now realise the problem likely was not getting the data in, but the data out, as it seems the data that is inputted affects the outgoing data construction.

This is probably the solution and will try it a bit later on

//Depending on where you want the result, change the following
// msg.payload.LVZ_ID = LVZ_ID1;
//to something like this....
msg.payload= LVZ_ID1;

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