@parallaxcontrol/node-red-control
Advanced tools
Comparing version 1.0.50 to 1.0.51
@@ -8,40 +8,55 @@ const { exec } = require('child_process'); | ||
node.on('input', function(msg) { | ||
let command = `/var/www/html/commands/cm4ProDigitalInput.sh`; // Define command here for better scope management | ||
// Execute the command if it's set | ||
if (command) { | ||
exec(command, (error, stdout, stderr) => { | ||
if (error) { | ||
node.error(`Execution Error: ${stderr}`, msg); | ||
msg.payload = `Error: ${stderr}`; | ||
node.send(msg); | ||
return; | ||
} | ||
// Object to store the last known state of the inputs | ||
let lastState = { DIN1: null, DIN2: null }; | ||
stdout = stdout.trim(); // Trim to avoid issues with newline or space in comparisons | ||
// Output objects for each pin | ||
var outputs = { | ||
DIN1: { Value: false }, | ||
DIN2: { Value: false } | ||
}; | ||
let output1 = { payload: null }; | ||
let output2 = { payload: null }; | ||
// Polling function to execute the command | ||
const pollGpioStatus = () => { | ||
let command = `/var/www/html/commands/cm4ProDigitalInput.sh`; | ||
exec(command, (error, stdout, stderr) => { | ||
if (error) { | ||
node.error(`Execution Error: ${stderr}`); | ||
node.status({ fill: "red", shape: "ring", text: "Error executing command" }); | ||
return; | ||
} | ||
if (stdout === "DIN1 Status: 0") { | ||
output1.payload = false; | ||
} else if (stdout === "DIN1 Status: 1") { | ||
output1.payload = true; | ||
} else if (stdout === "DIN2 Status: 0") { | ||
output2.payload = false; | ||
} else if (stdout === "DIN2 Status: 1") { | ||
output2.payload = true; | ||
} else { | ||
node.warn("Unexpected stdout content"); | ||
node.status({ fill: "yellow", shape: "ring", text: "Warning: Unexpected output" }); | ||
return; | ||
stdout = stdout.trim(); | ||
var lines = stdout.split('\n'); | ||
lines.forEach(line => { | ||
let [pinStatus, status] = line.split(': '); | ||
let pin = pinStatus.trim().split(' ')[0]; // Assumes format "DIN1 Status" | ||
let state = status.trim() === '1'; | ||
//flip the state so that 0 is true and 1 is false | ||
state = !state; | ||
if (lastState[pin] !== state) { | ||
lastState[pin] = state; // Update the last known state | ||
outputs[pin].Value = state; // Update the output value | ||
// Prepare the message object for each pin | ||
if (pin === "DIN1") { | ||
node.send([{ payload: outputs[pin] }, null]); // Send only on first output | ||
} else if (pin === "DIN2") { | ||
node.send([null, { payload: outputs[pin] }]); // Send only on second output | ||
} | ||
} | ||
}); | ||
node.send([ [output1], [output2] ]); // Send the outputs appropriately | ||
}); | ||
} else { | ||
node.error("No command set", msg); | ||
node.status({ fill: "red", shape: "ring", text:"Error: No command configured"}); | ||
} | ||
//node.status({ fill: "green", shape: "dot", text: "Output processed successfully" }); | ||
}); | ||
}; | ||
// Start polling at the specified interval (250ms) | ||
const intervalId = setInterval(pollGpioStatus, 250); | ||
// Clean up on node close | ||
node.on('close', function() { | ||
clearInterval(intervalId); // Stop polling when the node is redeployed or Node-RED is stopped | ||
}); | ||
@@ -52,1 +67,3 @@ } | ||
}; | ||
{ | ||
"name": "@parallaxcontrol/node-red-control", | ||
"version": "1.0.50", | ||
"version": "1.0.51", | ||
"description": "A comprehensive package of Node-RED nodes designed to seamlessly integrate with the Parallax Control Engine, offering enhanced control capabilities for AV Automation.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
86441
1103