We have a fairly simple node, executing an external program. Upon incomming message node should update its status and display "executing". However node status doesn't change. Only in the end node status is "All operations finished".
Sourcecode of testnode.js
"use strict";
const execFile = require('child_process').execFileSync;
let externalProg = __dirname + "/wait.sh";
module.exports = function (RED) {
function testnode(config) {
RED.nodes.createNode(this, config);
var node = this;
node.on('input', function (msg, send, done) {
// For maximum backwards compatibility, check that send exists.
// If this node is installed in Node-RED 0.x, it will need to
// fallback to using `node.send`
send = send || function () { node.send.apply(node, arguments) }
done = done || function () { if (arguments.length > 0) node.error.apply(node, arguments) }
node.status({fill:"yellow",shape:"dot",text: "Executing ..."});
try {
let res = execFile(externalProg, { encoding: "utf8" }).trim();
msg.payload=res;
}
catch (error) {
console.log(error);
done("Error executing external file. Execute permisson set?", msg);
node.status({fill:"red",shape:"dot",text: "Error executing file ..."})
return;
}
send(msg);
// If an error is hit, report it to the runtime
node.status({fill:"green",shape:"dot",text: "All operations finished."})
if (done) {
done();
}
});
}
RED.nodes.registerType("testnode", testnode);
}
If you want to try it, you can use package.json und testnode.html from Reading from serial. Works in sample-js file, but when running in node-red serial port gets closed
Script simulating an external program
#!/bin/bash
sleep 5s
echo "Done waiting"
Flow:
[{"id":"d24c6e9f.28db78","type":"inject","z":"b451655f.5db818","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":400,"y":280,"wires":[["465016d8.ef75a"]]},{"id":"465016d8.ef75a","type":"testnode","z":"b451655f.5db818","name":"testnode","serialport":"/dev/serial0","x":640,"y":280,"wires":[["f96506af.bb3e48"]]},{"id":"f96506af.bb3e48","type":"debug","z":"b451655f.5db818","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":280,"wires":[]}]
What am I doing wrong? Why is there no node status displaying "Executing..."?
PS: I know maximum execution time for a node is 15 seconds. The real script will take 10 seconds at max, so that won't be a problem.