Function Node Programming-Part 1

Introduction The function node is used to run JavaScript code against the msg object. The function node accepts a msg object as input and can return 0 or more message objects as output. This message object must have a payload property (msg.payload), and usually has other properties depending on the proceeding nodes. In order to use the function node you will need a basic understanding of JavaScript. In this series of tutorials will be covering JavaScript basics to get you started using the function node. Variables Context Variables Using a Single Variable or an Object Creating New Message Objects Returning from the Function Node Returning a Message before the end of a Function Variables In JavaScript you need to create a variable before you can use it. Variables are declared and assigned usually at the same time but that can be done separately. var name; //declared name=”steve”; assigned There are three ways to create a variable using the keywords var, let and const. var name=”steve” //declared and assigned let name=”steve” const name=”steve” Let is relatively new so in older scripts you will only see the var and const declarations. Let is commonly used in newer scripts in place or var

Continue reading

Using Nodejs Modules in Node-Red

Because node-red is a nodejs applications it is possible to use nodejs modules in node-red. Depending on the version of node-red that you are using there are two ways of doing this: Editing the settings File -All versions Setup tab in the function node -1.3 and above Click to rate this post! [Total: 2 Average: 5]

Continue reading

Using Node-Red with Influxdb

Influxdb is specially designed for time series data and as such it is a popular choice for storing sensor type data. Influxdb underwent a major change in version 2.0 and so you need to careful what version you are using. Click to rate this post! [Total: 1 Average: 5]

Continue reading

Node-Red SQlite- Using a Prepared Statement

Passing database command in the topic risks a SQL injection as the payload isn’t sanitised unless you do it. An alternative and somewhat easier method is to use a prepared statement. Click to rate this post! [Total: 1 Average: 5]

Continue reading

Using Subflows and Groups in Node-Red

A subflow is a collection of nodes that appear as a single node in the workspace. They also appear in the node palette and can be added to a flow like any other node. They are effectively reusable groups of nodes much like sub routines in traditionally programs. Any changes to the subflow are effective immediately in all flows using that subflow Click to rate this post! [Total: 0 Average: 0]

Continue reading

Node-Red and JSONata for Beginners

JSONata is a lightweight query and transformation language for JSON data and allows queries to be carried out directly on JSON data. —ref The alternative,and the one I most often use is to convert JSON to JavaScipt and then query it using JavasScript functions. Click to rate this post! [Total: 0 Average: 0]

Continue reading

Function Node Programming-Arrays,Objects and Loops

To work with node-red function node you will need a basic understanding of JavaScript objects and arrays. An object is a collection of key value pairs separated by a comma and enclosed in braces ({}) Example: let data={“voltage”:100,current:2}; Note that the key doesn’t need to be in quotes but it  often is. An array is simple a list with each item separated by a comma and enclosed in square brackets. Example: let data=[“voltage”,100,”current”,2]; Notice that is can be mixed strings and numbers and the strings must be in quotes. Accessing object properties To access the current in: let data={“voltage”:100,current:2}; we can use either of the formats shown below: let current =data.current; let current=data[“current”]; Note if the key is a variable then we need to use the square bracket format. let current=data[current]; For an array we need to use the index which by convention starts at index 0. So to get the current value we use: let current=data[3]; //=2 Using Loops Loops let you repeat an action. There are several loops available they are for,while, do while. By far the most common one is the for loop. The general format is: for (begin; condition; step) { // … loop body …

Continue reading

Using The Table DashBoard UI Widget Node

The table  dashboard ui widget node is used to add tabular data to a dashboard. The node is based on the tabulator module which you can read about here and see examples here. Click to rate this post! [Total: 0 Average: 0]

Continue reading

Using the Node-Red Email Node

The node-red email node most commonly used is the node-red-node-email which consists of three nodes. A send node receive node  MTA (transfer node) Click to rate this post! [Total: 0 Average: 0]

Continue reading