In this post i will share ,how to use  Node Red Complete Node

A Complete Node can be use to monitor execution of specific line of a node.

When the node Monitor by a Complete node has  completed execution , it will pass the msg.payload  from the monitored node to the Complete Node.

after that ,User can use the Complete Node to trigger other process.

 

Lets Build the Complete Node

Step 1

We Will build the Node to be Monitored by Complete Node.

Drag out  an inject node and configure as below

Step 2

Build the Count and Trigger Node

Drag out the Function Node and paste the Code below inside the Function Node at the On Message Tab Area.

There  are 2 component s. the interval function will keep adding count by 1000 ( 1 Second )

While the SetTimeOut  , parameter is set to  5000 ( 5 Second ) to time out . In the SetTimeOut  function , first it will clear the Interval  , update the node Status , update the lastest node count to payload.

 

 

var count = 0;

// Start counting

var interval = setInterval(function() {

    count++;

    node.status({ text: ‘Count: ‘ + count });

}, 1000); // Count every 1 second

// Trigger message after 5 seconds

setTimeout(function() {

// Clear the Interval

    clearInterval(interval);

// Update the Node Status UI when Counting

    node.status({ text: ‘Message triggered!’, fill: ‘green’, shape: ‘dot’ });

// Send the Node Count

    node.send({ payload: count }); // Send the count as the payload

    node.done(); // Mark the current node as complete

}, 5000);

return null;

 

 

Step 3

Drag Out  Debug Node , and joint all 3 Nodes as below

Step 4

Drag out the Complete Node , configure as below

 

Step 5 

Drag out the Function Node  and paste the code below into the function node on message tab .

This Function node will get the msg.payload value from the  “Count and Trigger ” Function  passed to Complete Node

 

var count = msg.payload;

msg.payload = “Count completed: ” + count + ” seconds”;

return msg;

Step 6

Drag out the debug node and joint the node as below , Trigger the Inject Node and observe the result

Results

 

Check out  how to declare global Variable in Node Red

 



Credit goes to the respective owner!

Leave a Reply

Your email address will not be published. Required fields are marked *