Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

58 rindas
2.0KB

  1. module.exports = function(RED) {
  2. function InterruptFlowUltimate(config) {
  3. RED.nodes.createNode(this,config);
  4. this.config = config;
  5. var node = this;
  6. setNodeStatus({ fill: "green", shape: "ring", text: "-> pass" });
  7. node.bInviaMessaggio = true; // Send the message or not
  8. this.on('input', function (msg) {
  9. var sTriggerTopic = node.config.triggertopic.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '') || "trigger"; // Topic controlling the bInviaMessaggio
  10. var sIncomingTopic = "";
  11. if (msg.hasOwnProperty("topic")) {
  12. // 06/11/2019
  13. sIncomingTopic = msg.topic.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, ''); // Cut unwanted Characters
  14. if (sIncomingTopic == sTriggerTopic && ToBoolean(msg.payload) === true) {
  15. node.bInviaMessaggio = true;
  16. setNodeStatus({ fill: "green", shape: "dot", text: "-> pass" });
  17. return;
  18. } else if (sIncomingTopic==sTriggerTopic && ToBoolean(msg.payload)===false){
  19. node.bInviaMessaggio = false;
  20. setNodeStatus({ fill: "red", shape: "dot", text: "|| stop" });
  21. return;
  22. }
  23. }
  24. if (node.bInviaMessaggio) node.send(msg);
  25. });
  26. function setNodeStatus({fill, shape, text})
  27. {
  28. var dDate = new Date();
  29. node.status({fill: fill,shape: shape,text: text + " (" + dDate.getDate() + ", " + dDate.toLocaleTimeString() + ")"})
  30. }
  31. function ToBoolean( value ) {
  32. var res = false;
  33. if (typeof value === 'boolean') {
  34. res = value;
  35. }
  36. else if( typeof value === 'number' || typeof value === 'string' ) {
  37. // Is it formated as a decimal number?
  38. if( decimal.test( value ) ) {
  39. var v = parseFloat( value );
  40. res = v != 0;
  41. }
  42. else {
  43. res = value.toLowerCase() === "true";
  44. }
  45. }
  46. return res;
  47. };
  48. }
  49. RED.nodes.registerType("InterruptFlowUltimate",InterruptFlowUltimate);
  50. }