Browse Source

Added the Last value change date/time in the status.

master
Massimo 5 years ago
parent
commit
cde964bce3
4 changed files with 40 additions and 41 deletions
  1. +5
    -0
      CHANGELOG.md
  2. +2
    -2
      boolean-logic-ultimate/BooleanLogicUltimate.html
  3. +32
    -38
      boolean-logic-ultimate/BooleanLogicUltimate.js
  4. +1
    -1
      package.json

+ 5
- 0
CHANGELOG.md View File

# node-red-contrib-boolean-logic-ultimate # node-red-contrib-boolean-logic-ultimate
<p> <p>
<b>Version 1.0.5</b><br/>
- Added the Last value change date/time in the status.<br/>
- Correction in the in-line help<br/>
</p>
<p>
<b>Version 1.0.4</b><br/> <b>Version 1.0.4</b><br/>
- Added the option to initialize the undefined inputs with true or false. Thanks to this, the node is immediately operative (will not wait until all topis arrives).<br/> - Added the option to initialize the undefined inputs with true or false. Thanks to this, the node is immediately operative (will not wait until all topis arrives).<br/>
</p> </p>

+ 2
- 2
boolean-logic-ultimate/BooleanLogicUltimate.html View File

<script type="text/x-red" data-help-name="BooleanLogicUltimate"> <script type="text/x-red" data-help-name="BooleanLogicUltimate">
<p>The node performs Boolean logic on the incoming payloads.<br/> <p>The node performs Boolean logic on the incoming payloads.<br/>
<a href="https://www.paypal.me/techtoday" target="_blank"><img src='https://img.shields.io/badge/Donate-PayPal-blue.svg?style=flat-square' width='30%'></a> <a href="https://www.paypal.me/techtoday" target="_blank"><img src='https://img.shields.io/badge/Donate-PayPal-blue.svg?style=flat-square' width='30%'></a>
<br/><br/>
The node performs 3 checks (<b>AND,OR,XOR</b>) on the incoming boolean payloads and outputs the result at the same time, as follow:<br/> The node performs 3 checks (<b>AND,OR,XOR</b>) on the incoming boolean payloads and outputs the result at the same time, as follow:<br/>
- Output "AND": true or false<br/> - Output "AND": true or false<br/>
- Output "OR": true or false<br/> - Output "OR": true or false<br/>
</ol> </ol>
<br/> <br/>


<bi How inputs are handled:</i><br />
<i> How inputs are handled:</i><br />
All incoming msg.payloads are converted into a boolean value according to the following rules (this applies to all boolean logic nodes): All incoming msg.payloads are converted into a boolean value according to the following rules (this applies to all boolean logic nodes):
<ol> <ol>
<li>Boolean values are taken as-is.</li> <li>Boolean values are taken as-is.</li>

+ 32
- 38
boolean-logic-ultimate/BooleanLogicUltimate.js View File

// Helper for the config html, to be able to delete the peristent states file // Helper for the config html, to be able to delete the peristent states file
RED.httpAdmin.get("/stateoperation_delete", RED.auth.needsPermission('BooleanLogicUltimate.read'), function (req, res) { RED.httpAdmin.get("/stateoperation_delete", RED.auth.needsPermission('BooleanLogicUltimate.read'), function (req, res) {
//node.send({ req: req }); //node.send({ req: req });
DeletePersistFile(req.query.nodeid);
// Detele the persist file
//var _node = RED.nodes.getNode(req.query.nodeid); // Gets node object from nodeit, because when called from the config html, the node object is not defined
var _nodeid = req.query.nodeid;
try {
if (fs.existsSync("states/" + _nodeid.toString())) fs.unlinkSync("states/" + _nodeid.toString());
} catch (error) {
}
res.json({ status: 220 }); res.json({ status: 220 });
}); });


var contents = fs.readFileSync("states/" + node.id.toString()).toString(); var contents = fs.readFileSync("states/" + node.id.toString()).toString();
if (typeof contents !== 'undefined') { if (typeof contents !== 'undefined') {
node.jSonStates = JSON.parse(contents); node.jSonStates = JSON.parse(contents);
node.status({fill: "blue",shape: "ring",text: "Loaded persistent states (" + Object.keys(node.jSonStates).length + " total)."});
setNodeStatus({fill: "blue",shape: "ring",text: "Loaded persistent states (" + Object.keys(node.jSonStates).length + " total)."});
} }
} catch (error) { } catch (error) {
node.status({fill: "grey",shape: "ring",text: "No persistent states"});
setNodeStatus({fill: "grey",shape: "ring",text: "No persistent states"});
} }
} else { } else {
node.status({fill: "yellow",shape: "dot",text: "Waiting for input states"});
setNodeStatus({fill: "yellow",shape: "dot",text: "Waiting for input states"});
} }




// 14/08/2019 If the inputs are to be initialized, create a dummy items in the array
// 14/08/2019 If some inputs are to be initialized, create a dummy items in the array
initUndefinedInputs(); initUndefinedInputs();


fs.writeFileSync("states/" + node.id.toString(),JSON.stringify(node.jSonStates)); fs.writeFileSync("states/" + node.id.toString(),JSON.stringify(node.jSonStates));
} catch (error) { } catch (error) {
node.status({fill: "red",shape: "dot",text: "Node cannot write to filesystem: " + error});
setNodeStatus({fill: "red",shape: "dot",text: "Node cannot write to filesystem: " + error});
} }
} }
SetResult(resAND, resOR, resXOR, node.config.topic); SetResult(resAND, resOR, resXOR, node.config.topic);
} else } else
{ {
node.status({ fill: "grey", shape: "ring", text: "Saved (" + (msg.hasOwnProperty("topic") ? msg.topic : "empty input topic") + ") " + value});
setNodeStatus({ fill: "grey", shape: "ring", text: "Saved (" + (msg.hasOwnProperty("topic") ? msg.topic : "empty input topic") + ") " + value});
} }
} else } else
{ {
} }
} }
else if(keyCount > node.config.inputCount ) { else if(keyCount > node.config.inputCount ) {
node.warn(
(node.config.name !== undefined && node.config.name.length > 0
? node.config.name : "BooleanLogicUltimate")
+ " [Logic]: More than the specified "
+ node.config.inputCount + " topics received, resetting. Will not output new value until " + node.config.inputCount + " new topics have been received.");
node.jSonStates = {};
DeletePersistFile(node.id);
DisplayUnkownStatus();
setNodeStatus({ fill: "gray", shape: "ring", text: "Reset due to unexpected new topic"});
DeletePersistFile();
} else { } else {
node.status({ fill: "green", shape: "ring", text: " Arrived topic " + keyCount + " of " + node.config.inputCount});
setNodeStatus({ fill: "green", shape: "ring", text: "Arrived topic " + keyCount + " of " + node.config.inputCount});
} }
} }
}); });
if (removed) { if (removed) {
// This node has been deleted // This node has been deleted
// Delete persistent states on change/deploy // Delete persistent states on change/deploy
DeletePersistFile(node.id);
DeletePersistFile();
} else { } else {
// This node is being restarted // This node is being restarted
} }
done(); done();
}); });


function DeletePersistFile (_nodeid){
function DeletePersistFile (){
// Detele the persist file // Detele the persist file
var _node = RED.nodes.getNode(_nodeid); // Gets node object from nodeit, because when called from the config html, the node object is not defined
try { try {
if (fs.existsSync("states/" + _nodeid.toString())) fs.unlinkSync("states/" + _nodeid.toString());
_node.status({fill: "red",shape: "ring",text: "Persistent states deleted ("+_nodeid.toString()+")."});
if (fs.existsSync("states/" + node.id.toString())) fs.unlinkSync("states/" + node.id.toString());
setNodeStatus({fill: "red",shape: "ring",text: "Persistent states deleted ("+node.id.toString()+")."});
} catch (error) { } catch (error) {
_node.status({fill: "red",shape: "ring",text: "Error deleting persistent file: " + error.toString()});
setNodeStatus({fill: "red",shape: "ring",text: "Error deleting persistent file: " + error.toString()});
} }
node.jSonStates = {}; // Resets inputs node.jSonStates = {}; // Resets inputs
// 14/08/2019 If the inputs are to be initialized, create a dummy items in the array // 14/08/2019 If the inputs are to be initialized, create a dummy items in the array
if (node.sInitializeWith !== "WaitForPayload") if (node.sInitializeWith !== "WaitForPayload")
{ {
var nTotalDummyToCreate = Number(node.config.inputCount) - Object.keys(node.jSonStates).length; var nTotalDummyToCreate = Number(node.config.inputCount) - Object.keys(node.jSonStates).length;
RED.log.info("BooleanLogicUltimate: Will create " + nTotalDummyToCreate + " dummy (" + node.sInitializeWith + ") values")
for (let index = 0; index < nTotalDummyToCreate; index++) {
node.jSonStates["dummy" + index] = node.sInitializeWith === "false" ? false : true;
}
if (nTotalDummyToCreate > 0) { if (nTotalDummyToCreate > 0) {
setTimeout(() => { node.status({fill: "green",shape: "ring",text: "Initialized " + nTotalDummyToCreate + " undefined inputs with " + node.sInitializeWith});}, 4000)
RED.log.info("BooleanLogicUltimate: Will create " + nTotalDummyToCreate + " dummy (" + node.sInitializeWith + ") values")
for (let index = 0; index < nTotalDummyToCreate; index++) {
node.jSonStates["dummy" + index] = node.sInitializeWith === "false" ? false : true;
}
setTimeout(() => { setNodeStatus({fill: "green",shape: "ring",text: "Initialized " + nTotalDummyToCreate + " undefined inputs with " + node.sInitializeWith});}, 4000)
} }
} }
} }


function setNodeStatus({fill, shape, text})
{
node.status({fill: fill,shape: shape,text: text + " (Last " + new Date().toLocaleString() + ")"})
}

function CalculateResult(_operation) { function CalculateResult(_operation) {
var res; var res;
return res; return res;
}; };
function DisplayUnkownStatus () {
node.status(
{
fill: "gray",
shape: "ring",
text: "Reset due to unexpected new topic"
});
};

function SetResult(_valueAND, _valueOR, _valueXOR, optionalTopic) { function SetResult(_valueAND, _valueOR, _valueXOR, optionalTopic) {
node.status({fill: "green",shape: "dot",text: "(AND)" + _valueAND + " (OR)" +_valueOR + " (XOR)" +_valueXOR});
setNodeStatus({fill: "green",shape: "dot",text: "(AND)" + _valueAND + " (OR)" +_valueOR + " (XOR)" +_valueXOR});
if (_valueAND!=null){ if (_valueAND!=null){
var msgAND = { var msgAND = {

+ 1
- 1
package.json View File

{ {
"name": "node-red-contrib-boolean-logic-ultimate", "name": "node-red-contrib-boolean-logic-ultimate",
"version": "1.0.4",
"version": "1.0.5",
"description": "A set of Node-RED enhanced boolean logic, with persisten values after reboot and more", "description": "A set of Node-RED enhanced boolean logic, with persisten values after reboot and more",
"author": "Supergiovane (https://github.com/Supergiovane)", "author": "Supergiovane (https://github.com/Supergiovane)",
"dependencies": { "dependencies": {

Loading…
Cancel
Save