@parallaxcontrol/node-red-control
Version:
A comprehensive package of Node-RED nodes designed to seamlessly integrate with the Parallax Control Engine, offering enhanced control capabilities for AV Automation.
51 lines (38 loc) • 1.78 kB
JavaScript
const fs = require('fs');
const { exec } = require('child_process');
const net = require('net');
//send command to device
module.exports = function (RED) {
function BiampTesiraCommand(config) {
RED.nodes.createNode(this, config);
var node = this;
this.ipAddress = config.ip;
this.username = config.user;
this.password = config.pass;
// Path to the named pipe for sending commands and reading responses
//const pipePath = '/var/www/html/commands/ssh_command_output_pipe';
//let pipeStream = null;
// Start reading from the pipe as soon as the node is initialized
//readPipe();
node.on('input', function(msg) {
let command;
// Construct the command string
command = `/var/www/html/commands/ssh_command_pipe.sh "${msg.payload}"`;
//command = `/usr/bin/expect /var/www/html/commands/send_cmd.exp "${msg.payload}"`;
// Run the command script
//msg.payload = `biamp-tesira-command.js, Sending command to ssh_command_pipe.sh: ${command}`;
//node.send(msg);
exec(command, (error, stdout, stderr) => {
if (error) {
msg.payload = `Error in biamp-tesira-command.js, Sending command to ssh_command_pipe.sh: ${error}, ${stdout}, ${stderr}`;
node.send(msg);
node.warn(`Error: ${stderr}`);
node.error(`Error: ${stderr}`, msg);
node.status({ fill: "red", shape: "dot", text: "Error" });
return;
}
});
});
}
RED.nodes.registerType("biamp-tesira-command", BiampTesiraCommand);
};