Core Nodes - 1

14 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.14
List Price:  €93.07
You save:  €27.92
£55.73
List Price:  £79.62
You save:  £23.88
CA$95.61
List Price:  CA$136.60
You save:  CA$40.98
A$106.30
List Price:  A$151.87
You save:  A$45.56
S$94.64
List Price:  S$135.20
You save:  S$40.56
HK$546.91
List Price:  HK$781.33
You save:  HK$234.42
CHF 63.50
List Price:  CHF 90.72
You save:  CHF 27.21
NOK kr764.69
List Price:  NOK kr1,092.46
You save:  NOK kr327.77
DKK kr485.92
List Price:  DKK kr694.20
You save:  DKK kr208.28
NZ$117
List Price:  NZ$167.15
You save:  NZ$50.15
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,661.98
List Price:  ৳10,946.16
You save:  ৳3,284.17
₹5,839.65
List Price:  ₹8,342.71
You save:  ₹2,503.06
RM331.75
List Price:  RM473.95
You save:  RM142.20
₦86,437.65
List Price:  ₦123,487.65
You save:  ₦37,050
₨19,492.21
List Price:  ₨27,847.21
You save:  ₨8,355
฿2,575.56
List Price:  ฿3,679.53
You save:  ฿1,103.97
₺2,262.43
List Price:  ₺3,232.18
You save:  ₺969.75
B$357.76
List Price:  B$511.10
You save:  B$153.34
R1,296.01
List Price:  R1,851.52
You save:  R555.51
Лв127.38
List Price:  Лв181.98
You save:  Лв54.60
₩95,113.23
List Price:  ₩135,881.87
You save:  ₩40,768.63
₪260.11
List Price:  ₪371.60
You save:  ₪111.49
₱3,999.61
List Price:  ₱5,713.97
You save:  ₱1,714.36
¥10,715.43
List Price:  ¥15,308.41
You save:  ¥4,592.98
MX$1,185.45
List Price:  MX$1,693.57
You save:  MX$508.12
QR254.79
List Price:  QR364.01
You save:  QR109.21
P955.69
List Price:  P1,365.33
You save:  P409.64
KSh9,427.65
List Price:  KSh13,468.65
You save:  KSh4,041
E£3,355.67
List Price:  E£4,794.02
You save:  E£1,438.35
ብር3,989.43
List Price:  ብር5,699.43
You save:  ብር1,710
Kz58,616.62
List Price:  Kz83,741.62
You save:  Kz25,125
CLP$66,326.02
List Price:  CLP$94,755.52
You save:  CLP$28,429.50
CN¥506.51
List Price:  CN¥723.62
You save:  CN¥217.11
RD$4,049.59
List Price:  RD$5,785.38
You save:  RD$1,735.78
DA9,420.19
List Price:  DA13,457.99
You save:  DA4,037.80
FJ$157.70
List Price:  FJ$225.30
You save:  FJ$67.59
Q542.62
List Price:  Q775.21
You save:  Q232.58
GY$14,613.08
List Price:  GY$20,876.73
You save:  GY$6,263.64
ISK kr9,792.30
List Price:  ISK kr13,989.60
You save:  ISK kr4,197.30
DH706.05
List Price:  DH1,008.69
You save:  DH302.63
L1,239.86
List Price:  L1,771.31
You save:  L531.44
ден4,010.92
List Price:  ден5,730.13
You save:  ден1,719.21
MOP$562.15
List Price:  MOP$803.11
You save:  MOP$240.95
N$1,302.54
List Price:  N$1,860.85
You save:  N$558.31
C$2,571.43
List Price:  C$3,673.63
You save:  C$1,102.20
रु9,317.58
List Price:  रु13,311.40
You save:  रु3,993.82
S/262.81
List Price:  S/375.46
You save:  S/112.65
K268.53
List Price:  K383.63
You save:  K115.10
SAR262.51
List Price:  SAR375.03
You save:  SAR112.52
ZK1,879.71
List Price:  ZK2,685.42
You save:  ZK805.70
L324.19
List Price:  L463.14
You save:  L138.95
Kč1,629.65
List Price:  Kč2,328.17
You save:  Kč698.52
Ft25,373.17
List Price:  Ft36,248.95
You save:  Ft10,875.77
SEK kr758.75
List Price:  SEK kr1,083.98
You save:  SEK kr325.22
ARS$61,468.94
List Price:  ARS$87,816.53
You save:  ARS$26,347.59
Bs482.36
List Price:  Bs689.12
You save:  Bs206.75
COP$272,946.91
List Price:  COP$389,940.87
You save:  COP$116,993.96
₡35,623.88
List Price:  ₡50,893.45
You save:  ₡15,269.56
L1,732.95
List Price:  L2,475.75
You save:  L742.80
₲523,151.84
List Price:  ₲747,391.81
You save:  ₲224,239.96
$U2,683.09
List Price:  $U3,833.15
You save:  $U1,150.06
zł281.85
List Price:  zł402.67
You save:  zł120.81
Already have an account? Log In

Transcript

Video 3.2 core nodes one. In this video, we will be looking at some of the core nodes of node red in the palette. These core nodes are the default set of nodes which are the building blocks for creating a flow. To begin with, we will learn about inject debug and function nodes. But we are already familiar with inject and debug nodes, aren't we, we created our first flow in video 2.2. Let's review a bit of what we know about these nodes.

Note that I'll be using node red running on the IBM Cloud by default hereafter, unless I specify explicitly, you can follow the lectures by running node red on the platform you are comfortable with. inject note as the name says it injects message payload into the flow. It is an input node, which means this inputs the message payload into the flow, you can add the name of the node in that label called name. You can manually trigger a flow by clicking the button on the inject node. There is also another way to automatically trigger the flow at regular intervals, or according to a schedule. Okay, but where are we supposed to use it?

You can use this functionality in places where we need our flow to do an operation at specific intervals, like sending reports via email to your superiors every day at 10am or getting notification or reminders to consume medications every day at 11am and 5pm. The ideas are endless, with no dread. The only limit is your imagination. Also know The payload can be anything not necessarily timestamp. It can also be a string number, Boolean, JSON object, buffer environment variable flow, global war. Wait, I don't know environment, buffer flow and global.

Okay, not to worry. We'll look into them as we unveil the mysteries of note read. By the way, we have some unfinished business with a timestamp. So first Can we try injecting it once at two second intervals, and then continuously at say, five second intervals. For this, we need to mark the inject once after every two seconds every time the flows are started, and then change the repeat none to interval for every five seconds. After setting up the inject node, to view the output, we need the debug node Let us connect that to now deploy the flow.

Note that the inject node starts to trigger the flow after two seconds automatically once we deploy. Okay, we are getting those random numbers again. Let's check what they are. It is the current time in milliseconds since January 1 1970. If only it was legible to understand the current time, it is actually legible. You can click on it to see the different time formats.

If you change one, the rest of the message payloads will all be changed to that format. Now we can finally understand what those random numbers mean. And remember what this time means. Did you think that it means the time of injection from the input node? If yes, you're right. Okay, now that we've understood how that works, I want you to send a JSON object with keys flavor and toppings.

With the payload ice cream. You can do that by selecting Jason and clicking the dots to enter the editor window. Here, you can add a JSON object and formatted if necessary. I also want you to set the topic to the stage you're in. It may also be the stage where you're going to swallow the ice cream. I want this message object to be displayed every 10 seconds.

Have you got something like this? If yes, congrats. Note that the maximum interval you can set here is 24 days. Now let us see the other two options that interval between times and at a specific time. The first one is used when you want to trigger a flow every x number of minutes between say 1pm to 2pm on specific days. The second one is used when we want to trigger the flow at a specific time on a specific day or days.

If multiple times are needed to be configured, then you must use multiple inject nodes. Okay, now that we've covered all the functionalities in inject node, let's go to the debug node. Here also, you can add the name of the node in the label called name. By default, the output will be set to message dot payload. You can set it to complete message object. Or you can also use a JSON data expression to output the specific JSON properties.

I'm going to select Jason data here, you'll soon know why. You can mark the system console. To send all messages to the runtime log. You can check the node status to send short, a maximum of 32 characters to the status text under the debug node. Okay, you see I scream example we saw before and write the JSON data expression to output the topping property alone. You can do that by clicking those three dots to enter the editor window.

Like we saw in the JSON data exerciser. This also has a space to enter sample JSON object, the expression editor and the output. Note that you have to copy the JSON object we got from the inject node and put it inside the payload property. Because remember, we added the JSON object in the payload property of the message object. We can get the toppings this way. Okay, now click Done.

I want you to check both of those fields in the debug node to see what happens. Okay, deploy your application and check out the changes. Oops. I didn't change the inject node. Let me change it. Now deploy.

There you go. Now, you may want to know where you can check the log details. If you're using node red running on your laptop, or Raspberry Pi or on your phone You can check the log in the command prompt itself. If you're running node red on IBM Cloud like me, then there are two ways to view the logs. You can either install c li and view the log in the interface, or else, you can go to your app page and click on the logs stamp on your left to check out the logs. And obviously, the easiest way would be the IBM logs.

I have included the link to guide you in installing the CLA if you want to. Note that it is always a good practice to disable the debug nodes which are not in use. Now that you're familiar with inject and debug nodes, let's add the function node to our flow. It'll be under function category in the pallet, drag it and just hover it over the existing wire to connect it between them. Flow automatically. Double click on it.

To open its properties, you can see an editor. This is the place where you can add JavaScript code to manipulate the message object pass through it. Here you can see that there is already a line present return message to return the message object. If we don't return the message object, then the flow stops and throws an error. If the function returns null, then no message is passed on and the flow stops. The name of the node can be edited or added under the name label.

Besides the label, there is an option to save the function node as a library or to open the library and reuse the already saved ones. Below the editor there is a space to mention the number of outputs. With this we can Understand that the function node accepts a message object as input, and outputs zero or more message objects. Okay, now let's try out the function node. I have included a flow file in this lecture, you can export it into your editor, I have explained the various features of the function node with example flows. Now, the inject node here contains a text payload called ice cream with a topic called butterscotch.

You can edit the existing message property or add a new property inside the function node and that is what I have done. I have configured the debug node to show the complete message object. You can see the changes made to the message object. You can also see that the output type is specified, along with the object and topic names. In this function, I have defined a new message object, and I'm returning the same. In this next function node, and getting the current date and time using the date object we saw in video 3.1.

I'm instantiating the object and using its value in my message payload. One main property of the function node is that we can have multiple outputs. So here, I'm having to inject nodes, each with different topics. The function node here has two outputs. It also has an if else loop. Check the topic name and act accordingly.

The return statement has an array of two elements message and null in the if loop. This means that the first output will show the message object, and there'll be no output shown in the second output. In the L statement, I have defined a new message object with its payload as the topic of the message object. This returns an array, which outputs the new message object in the second output. You can check that here. Next, our arrays in functions.

Yeah, none of the inject nodes have strings. The function node here has three message objects. Each with an integer payload. The return value is an array of three message objects. But note that the output is set to one to only the first message object is the output. In the next one, the function node returns three message objects in an array with three outputs.

So, each output corresponds to a message object. So all three are shown as output. The next one here features an array within an array. Here, there are three message objects. But the return string has an array with two elements, message one, and an array of message two and message three, and the output here is two. So the message one object gets outputted in output One and the array of message two and message three gets shown in output to function node has even more features.

We'll discuss them in the upcoming videos. In this video we saw the core nodes, inject debug and function node. In the next video, we will see the next set of coordinates and the rest of the features of the function node.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.