Using the Node Red Status Node

status-nodeIn Node red any node can report status information in the visual editor.

The screen shot below shows the mqtt node.

mqtt-node-status

It shows a green circle to indicate that it is connected and the text connected underneath the node.



The UI visual status is enabled by default but can be disabled in the menu>settings.

Node-red-Status-enable-ui

Although useful as a visual indicator it is even more  useful to have this status information available in the flow and to be able to take action based on the node status.

status-node-locationTo do this you need to add the status node to your flow.

You will find the status node under the input nodes.

If you add this node to the flow and open the flow you can select the node/nodes you want to receive status information for as shown below:

status-select-nodes

In the above I have selected the MQTT node. The screen shot below shows my example flow.status-node-example-flow
The status node sends a msg whenever the status of the monitored node/nodes changes.

This message consists of two objects.

  • status object – used to get status information
  • source object- Identifies source of message using the node id. Every node has a unique node id.

status-node-output
You can view the id of a node by clicking it and then clicking on the information pane in the far right.

view-node-id

To access these properties in a function or other node use:

msg.status.text and msg.status.source.id

In my simple flow the function node receives the status information from the status node and simply passes it on to the debug node.

Th screen shot below shows the status text changing as the mqtt node connects.

MQTT-Staus-information

You can take action based on the connection text in a function node using an if statement e.g.

if (msg.status.text=="node-red:common.status.connected")
{
DO Something
}

Because the status information is only sent when the status changes it is usually necessary to place the information in a global or flow object.

To do this pass the status msg into a function node that has the following code.

var mqtt_status=msg.status;
global.set('mqtt_status',mqtt_status);
return

The Status information can then be used anywhere in the flow.

Video

Here is a video that covers the above and also demonstrates using the status information to control when messages are published over MQTT.

Flow used in video

Displaying Status Information from Function Nodes

Your can display stays information from your own function nodes in the admin UI.

To do that use the following:

node.status(Object)

The object you pass can have three key value pairs:

  • fill – This is the fill colour can be: red, green, yellow, blue or grey
  • shape- Ring or Dot
  • Text – descriptive text

The screen shot below shows an example function configured to display status information using the following:

node.status({fill:"green",shape:"ring",text:"done"});

function-status

Related tutorials and Resources:

 

Please rate? And use Comments to let me know more
[Total: 1    Average: 5/5]

Leave a Reply

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