Struggling with exec node

I've been struggling to use the exec node to run a command that will work in a standard linux cli. The command sends a request to a thermostat in my home, and returns a JSON object with the current status of the thermostat. The command is:

echo -e '{"GET_SYSTEM": 0}\0\r' | nc 192.168.1.20 4242

It works perfectly in the Raspberry Pi terminal, but when I've tried using it in the exec node, I don't get the result I'd expect:

1 - If I add the command, as written above, to the "Command" field of the exec node, I get no message on the stdout, stderr or return code outputs of the node.

2 - I've tried changing to spawn mode, instead of exec node, and then I get a raw data buffer output, which I can't comprehend.

3 - I've tried "injecting" the command to the exec node as well, and this gives the same results.

Any pointers? Is there something obvious I'm missing?

can you show us the debug output of the spawn command - The node will try to parse it to a string - but if there are any non-ascii characters in there it will drop back to a buffer.

so you are actually running multiple commands because of the Piping. Try this, put the commands in a script then execute the script.

Hi @dceejay. Output using spawn mode (using the "copy value" button in the debug panel) looks like:

[39,123,34,71,69,84,95,83,89,83,84,69,77,34,58,32,48,125,0,13,39,32,124,32,110,99,32,49,57,50,46,49,54,56,46,52,46,50,52,48,32,52,50,52,50,10]

Hi @zenofmud. Do you mean, create a script file on the local filesystem, and trigger that from within node red?

that's just the command echo'd back :slight_smile:

but yeah why not try the tcp request node as that seems to be what you are doing... just sending a tcp command to port 4242

Solved! One of those things I'm embarrassed I didn't spot. The netcat command wasn't automatically closing the server connection after receiving data. Adding a short timeout flag to the end of the command sorted everything. :slight_smile:

1 Like

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