Weird scrambled output of exec node using bacnet readprop command

Have experienced problems with all available bacnet nodes for node red. So to try something else, bacnet stack was included in the docker container and is available through exec node.

For example can run this command:

readprop 111 19 1 description

This returns the description based on the specified arguments, great! So then I made an array of such commands and send them all to exec node. But the result is really weird, because the output gets scrambled and seemingly randomly distributed among the messages!

So I wondered, is this a problem with the readprop program? Is it a cli problem? Or is it an exec node problem? Here are some different attempts and results:

  1. Add a 1 sec delay in node red. Result: Success
  2. Loop in linux: Success
for i in {1..10}; do /usr/local/bacnet-stack/build/readprop 111 19 1 description; done
  1. Add a tag to be concatenated to the output of the command in node red: Fail
msg.payload = `echo "$( ${msg.payload} | tr -d '\r\n' ) ${msg.topic}"`;

Success means each command returns correct payload. This looks like a timing issue? Is there any known bug of exec node to mix up the output and messages?

Was surprised to see even the msg.payload (command) and msg.topic are scrambled in attempt 3).

Perhaps the exec node is spawning all the commands immediately. So I guess the stdout feeds from the individual processes will be merged as they arrive from the processes.

1 Like

In the exec node, have you set the Output to exec mode?

1 Like

Yes, I use "when the command is complete - exec mode" exclusively. Command is left empty, then appent msg.payload (checkbox checked). Timeout 10 seconds (don't think it matters as all commands are "instant". Finally "Hide console" for windows, but this is running on linux docker container so no gui anyway.

It gets weirder in another test I just did now. Instead of using some 3rd party readprop bacnet program, I made a simple linux script:

#!/bin/bash

# arg (number of seconds)
seconds=$1

sleep "$seconds"

echo "Slept for $seconds seconds."

Can run this from command line, works fine. Run it as a single message in exec node, runs fine. But run this as an array and send one message per item in the array, and it doesn't sleep!

Check out this function node:

const messages = [];
for(let i = 0; i < 10; i++){
  messages.push({
    topic: i,
    payload: `/tmp/test.sh ${i}`,
    payload2: `/tmp/test.sh ${i}`
  });
}

return [messages];

Result is, every second, debug node after exec node outputs "Slept for 0 seconds", then 1 seconds, then 2 seconds... up until 9 seconds! No sleep at all?

Or, perhaps all of them are executed in parallel? Still, the result is not scrambled, so each topic is according to the output of the command (nr of seconds).

Edit: Yup, reversed the order and indeed all are executed in parallel. Perhaps this causes problem for bacnet readprop program? Will have to look into a way of isolating that command somehow. Any way to configure exec node to run sequentially and NOT in parallel?

You can force them to be sequential using this flow.

1 Like

That's brilliant, thanks! So simple.

1 Like