Node-Red Example Flows

The idea of this page is to present simple flows or sub flows that solve a particular problem, and that can be used as part of larger projects.

If you have any suggestions then I would be glad to hear them just use the comment form at the bottom of the page.

———————–

Set Text Colour Of Text Dashboard Widget

The goal here is to change the text colour in a dashboard text widget but can also be applied to other widgets.

The flow consists of an inject node that send a simple text string and a change node to set payload properties for the colours.

set-colored text
The change node is shown below

set-colour-change

The work is done the text node where HTML is used to change the font colour which is passed into the node as variables from the change node.

set-colored text-2

Result

———————-

Splitting a Message Payload

In this simple project we will look at splitting a simple message payload, and then display the data in a text box and on gauges on a dashboard.

The payload consists of a simple string containing temperature and humidity readings separated by a ampersand (&).

{“topic”:”node1/temperatureandmoisture”,”payload”:”26.81&1024″,”qos”:0,”retain”:false,”_msgid”:”2b22bffa.9eff4″}

To split it we use the split method to split the string into an array.

The array will look like this [26.8,1024].

Next there are two main approaches to dealing with the data:

  • Place data in an Object
  • Assign data directly to message properties

Placing data in an Object

We place the data into a JavaScript object and assign to the payload before returning. The code is shown below.

var data=msg.payload;
var temp=data.split("&");
var out={};
out["temperature"]=temp[0];
out["humidity"]=temp[1];
msg.payload=out;
return msg;

The output would look like this.

{temperature:26.8,humidity:1024}

To display in a text box we change the value format form msg.payload to msg.payload.humidity as shown below.

test-box-change-1

To display on a gauge we need to insert change nodes to change as shown below:

change-node-1

Assign data directly to message properties

The second approach is simpler and we use a message property for humidity and temperature and now our code looks like this :

var data=msg.payload;
var temp=data.split("&");
msg.temperature=temp[0];
msg.humidity=temp[1];
return msg;

To display it in a text box set the value format to msg.humidity instead of msg.payload.

text-box-change

However if you want to display it on a gauge then the value must be in the msg.payload field.

To do this we can use change nodes set as follows:

text-box-change-2

Both Approaches use the same nodes but they are configured differently. The flow look like this:

Split-Payload-flow

The dashboard like this:

split-payload-dashboard

The flows for both approaches are available to download below:


—————————

Simple Keypad for Node-Red Flows

Download

————

Display last x Messages

Will display the last x messages. x is 10 by default and can be changed in the code.

Flow Diagram

last-messages-display

 

Download


Click to rate this post!
[Total: 2 Average: 5]

2 comments

  1. Hello Mr. Your blog is good. So i have many question about MQTT. because now i’m making a exam project about mqtt. Could I get have your contact email ?

Leave a Reply

Your email address will not be published.