Intro to Node-RED: Part 1 Fundamentals

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
You've probably heard a lot about Node-rRED and its importance in the IOT revolution. But what exactly is it? Simply put Node-RED is an open source visual editor that allows programmers of any level to rapidly interconnect physical i/o, cloud-based systems, databases, and most API's in any combination you can imagine. Node-RED is getting more and more support in the growing world of IOT and IIoT. If you're not using it you're missing out on an incredibly flexible and powerful tool. In this video I'm going to go over the fundamentals of Node-RED and show you how to build a simple project or flow to help you get started. Node-RED can be run on most modern computer systems including Windows, Mac, and Linux pcs or even lightweight computers like the Raspberry Pi or industrially hardened appliances like this groov AR1 which is what I'll be using for this workshop. Node-RED's website has instructions on how to get the application running on whatever system you're using but it's running on the groov AR1 by default. So I can just go over to Node-RED by going to my boxes host name:1880 and login with my admin user's credentials. This is a pretty big deal. By default Node-RED installations are wide open but on the groov AR1 we have added both HTTPS and authentication for you. Now I can see the main landing page for Node-RED with its three main sections. The Node palette on the left, the main workspace front and center, and the output pane on the right. The nodes on the left are organized into collapsible categories to sort your available nodes. You can also search for them in the filter at the top. Most of the nodes you see here are included by default called 'core nodes'. You can install external nodes to get more functionality as I'll explain later on. These two Opto nodes are included on the AR1 by default. Each node performs a specific function and what makes Node-RED so flexible and powerful is that the modular nodes are self-contained and reusable with most of the JavaScript program logic and API overhead hidden in these colored rounded boxes. You get new nodes into your program by clicking and grabbing them from the node palette and dragging them into the workspace. Here I've brought in one of the key core nodes 'the Inject node'. Node-RED uses flow-based programming and so to start the flow something will need to inject a message into the flow where the inject node pushes a timestamp in by default. As you can see by its label another key core node is the output debug node. so I'll drag one of those in now to if you check the info tab and then output pane it explains that the debug node displays the msg.payload from the flow by default. To actually see this message you'll need to come up here and switch to the debug tab. To edit a node double click it and a new pane will pop out. Here with the inject node you can see that the time stamp is going into msg.payload which is what the debug node will output to this window by default. So we don't need to change any settings but we do need to connect the pair. As you can see input nodes have a small icon on the left side of the node and output nodes have a small icon on the right. This represents what kind of action the node takes. In the case of the inject you get a small arrow, the debug has a couple of lines, and the catch has an exclamation point and so on. Also note that the timestamp node has one connection port on the right side. This is for the flow output of the node. And the output node has a connection port on the left side of the node this is for flow input. To wire two nodes together grab one connection port click and hold drag the wire over to another connection port and release. You can do this either left to right or right to left it doesn't matter. Now that they're connected we need to make the changes active by hitting the deploy button in the top right. Before changed nodes are deployed there's a small blue circle indicating that there are unsaved changes. After deploying you will see it go away and you know that the nodes are live currently the program represented by these nodes is running but not actively doing anything since no messages have been injected into the flow yet. Force an inject using the blue button tab coming out of the timestamp node. This injects unix time - a standard that measures the number of milliseconds elapsed since the first of January 1970. This number flows along the wire and gets displayed in the debug window by the output node. Node-RED recognizes this number as a time stamp. So I can click it to see the ISO representation, click it again to see the hexadecimal value, and click it once more to return to decimal. The debug shows the content of msg.payload which is what the inject node feeds. Let's say I want to see the time every second I can go back to the inject node select 'repeat' and change it to the interval of one second. Now I click done, deploy the changes, and I'll see the time appear once every second. To stop this I'll need to go back, turn the interval off, and save it once again. Now I can change what the inject node is inserting into the flow and I can change it from time stamp to a string message. To do that I double-click the node, click the drop down for time stamp, and make it the constant string 'hello world'. Click done, deploy, and inject to see the new payload. Now you've seen some basic inputs and outputs using the core nodes inject and debug. Let's see how we can use processing nodes that have both an input and an output to modify our data. Let's start with a simple change node. From the function section scroll down there and drag one onto the wire in between the two nodes I already have. You'll see it go from solid to dashed to indicate that it's going to automatically wire itself in. Double click the node to edit it and here I'll show you how to change the msg.payload and search for the word 'world' and replace it with another string 'from node red'. Click done, deploy, and inject again to see the modified flow. Here in the debug window I can see that it has changed the word 'world' to 'from Node-RED' so now I have the full string 'hello fromNode-RED' however this change node is relatively limited in what it can do and is not designed to loop or make complex logical decisions. Only follow the specific rules entered in this window. Thankfully there's an alternative - the function node. Which has very few limitations. So let's get rid of this one. You can delete wires by clicking on them and pressing delete. And you can get rid of nodes the same way. If you make any changes you're unhappy with you can use the shortcut control Z to undo them. Note that when I deleted the wires nothing happened to the nodes but when I delete the node the wires connected to it are deleted as well. This new function node is one of the most powerful in Node-RED. Once I connect it and edit it I can see that it exposes a block of JavaScript to the user and I can do whatever I wish within this language. In this example I'll show how it can replicate the change node functionality by creating a new string and using the replace function to look for the world 'world' and replace that with 'from Node-RED'. Then I can return a new object with this new string as the payload. I'll click done, deploy, and then inject the payload so that I can see the new flow in action. Here in the debug window I see that the exact same string is outputted as I got from the change node now to get a quick example of how new node packages are installed go over to the node-red menu click on manage palette and then navigate up to the install nodes tab. You can search for any package you'd like. Here but I'm going to search for the MS SQL package. This will allow me to connect to a Microsoft SQL database. I can click install and since this node has no extra dependencies I'm free to bring it in. Once it's done installing I can click close and scroll down to the storage section where I see the MS SQL node installed right below the core file nodes. So there you have it I have given you a brief overview of what the Node-RED interface contains how inject nodes can input information have it processed by different function nodes and output messages with the debug node. Using user-defined function nodes or community built packages.This simple flow based programming tool can do incredible things. For more information check out workshops opto22.com and node-red org thanks for watching
Info
Channel: Opto Video
Views: 454,053
Rating: undefined out of 5
Keywords: automation, opto 22, opto, opto22, automatizacion y control industrial, node-red, node red, ibm, iot, iiot, industrial, how to, fundamentals, basics, learn, what is node-red, learn node-red, automation 101, step by step, instruction, tutorial, lesson, flow, application, node-red for automation, snap, snap pac, pac, programable automation controller, plc, node-red tutorial, node red tutorial, nodered tutorial, internet of things
Id: 3AR432bguOY
Channel Id: undefined
Length: 9min 46sec (586 seconds)
Published: Wed Nov 01 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.