Search code examples
node-red

Node RED. Sending several inputs to the same exec node


I am sending 3 sensor measurements coming from mqttin nodes to an exec command that must have this content echo '1 2 3' | ./a.out where 1 2 3 is the data from the 3 mqttin nodes.

I am having difficulties creating that command that must be sent from the exec node to the terminal.

Edited:

Basically I am first testing the use of several sliders, a join where I combine the payload of each slider as a string and a debug node to check the output. My objective is to create a single string with the values coming from the slider, and then add the last part of the command "...|./a.out"

The sliders are just pretending to be mqttin nodes. But in this part there is no problem.

I am not able even to cocatenate the outputs from the sliders, what should I create? buffer, string, array, key/value object.. and how to add the last part of the command?

I can execute something like echo '1 2 3' | ./a.out and the output is another string like "1231 13 2", with a varying number of spaces separating each number. How can i obtain 3 integers from that?

I have checked many related questions and didn't find an answer.

Thank you.


Solution

  • To get the exact output you want it's probably going to take multiple nodes.

    • First up a join node set to output a key/value object

    enter image description here

    • next a function node to convert the 3 values into the string and add on the echo and pipe

    e.g.

    var keys = Object.keys(msg.payload)
    var string = "echo '"
    for (var k in keys) {
        string += msg.payload[keys[k]] + " "
    }
    
    msg.payload = string + "' | ./a.out";
    return msg;