Hey, in this in the next lecture, I will talk about messages and viable messages and various other
ways by which Newt can communicate with each other and pass data to each other.
So here will start with messages.
And I've already said a couple of examples here to walk you through and present some of the features
that you should know about with messages and how to use them.
Of course, there is documentation that you should really look at to get all of the details.
And I encourage you to do that.
Messaging as well as Flo's is a powerful way for data interchange within Flo's or across actually multiple
flows in your note read installation here.
I just want to keep things very, very practical and applicable to the project that you are about to
begin.
I've also used the documentation feature via the comment note.
She can see right here of a couple of common codes been doing that as well throughout this course where
I provide information that you should be aware of for each particular flow and to each particular tab.
So here, for example, I'll be using a bit of Jason, I'm giving you the origin of the Jason object
that I'm using as a test and also the link to the documentation that I've shown you here.
So look around for these bubbles that contain further information.
So let's have a look at messages that are said, the primary way of communication between notes.
I've got a bunch of inject notes here and actually to show you how these work, what I do is I will
disable them.
So you can see I have selected a bunch of notes and I can go here and enable or disable them.
So let's say that I want to disable these notes so they're not really it.
And available for execution, and that leaves me with just these two, I'm going to drill inside the
time stamp payload note and you can see that the payload of this node is actually a message.
Amstutz, the only thing that it can be.
And I've given it a particular value.
I've just taken a timestamp.
I'm going to show you how to do the same thing with the string in a moment.
Now, what happens is that this timestamp or whatever it is that you want to pass on to the next node
will be stored as payload of the message object.
So let's see what that means inside the debug node.
Just taking whatever I've got inside the payload attribute of the message object and I'm printing it
out.
So let's deploy the flow and I'm going to manually trigger the timestamp, inject mode and actually
switch to the debug messages view and see what we get on the other side.
So that's what we get.
So this is the message payload.
So just one component out of the message object.
And I think I've shown you this before.
This is a date, but you can scroll through a variety of representations for this same value right now.
Going to make a small change to my debug node.
So go in the node and then change the output from message dot payload to the complete message object.
And that will show us exactly what is being passed from one note to the other through messaging.
So clear debug window and then trigger the inject note in here is the complete message.
So instead the complete message.
We've got the payload which contains the data we already seen, plus this attribute here, a message
ID and depending on what else the message is, it may contain other types of attributes in here.
So now that we know that the message object contains other attributes, what it can do is copy that,
go into my debug mode, back into message and just replace the payload with the message ID and you can
probably guess what this is going to do.
It just gives us the message ID.
That may be useful in some circumstances, but in this case, it's more useful if we have the payload.
So I'm going to get this back into the payload configuration for the output.
And always deploy your flu when you make a change for the change to be effective.
OK.
It's back to normal now.
Want to take you back to a previous example, the DHC 22 example.
And I'm going to enable this flu so I can show you.
So here we've got a sequence of notes.
And of course, each note is connected to the next one and passes a data via a message.
Now, I want to have a closer look to what those messages look like and see the differences between
messages that are passed on and created by different notes.
So, again, I'm going to use a series of debug notes.
And just to keep this short, I'm just going to give them numbers.
So this is going to be the first one.
And I want to see the complete message object going to take out another one and connected to the trigger
load.
And I'm going to make that a two and complete message and another debug.
You know, for the DHT 22 Noad, and it's going to be number three, and again, I want to see the complete
message and I need to do that for the last one.
Actually, no, I don't need to.
So I will deploy this through and I will switch to debug clean it up and trigger this flow.
And I can see what is happening.
You've got the first debug node and here is its payload, the complete payload.
The second one looks like this as well.
Nothing fancy in it, but the third one, which is coming out of the twenty two node, you can see that
it contains more attributes.
So there is the message out there, like the other two messages, but then the rest contains information
that is specific to the twenty two node.
So there's a payload with a temperature and there's the humidity, whether it's valid and a few other
things such as that topic, location and sensory data that we have configured in the sensor node.
So just to show you that the actual message configuration depends on the node that creates the message,
but they all have a few shared attributes, such as the message ID and they all do have the payload
attribute.
OK, I'm going to disable the DHT 22 example flow so that it does not continue to produce output and
go back into my messages tab.
Let's continue with the example, so I'm going to disable the timestamp and the timestamp payload and
then enable these to so on and on, this is similar to the first example, except that I don't now have
a string payload so I can actually create payloads of different kinds, like string numbers, booleans,
et cetera.
I'm going to show you an adjacent example in a moment as well.
And whatever it is, it will just pass through to the next node, which should be able to do something
with it.
So the next node here is just the debug printing out the complete message.
Object to the monitor here and it looks like this.
I need to deploy Aikau and clean up and now trigger the InterCloud.
So there's the payload, the full payload object, I can switch back to the message payload only, you
know what this is about to do.
And it looks like this.
We just have the string coming through the debug window.
I just have a look at something more interesting.
And to do that, I will disable these two nodes and then enable the payload node, adjacent payload
node.
So what I've got in this inject node is a valid Jason document, which looks like this.
You can actually use a visual aid, which is very handy if you want to do some more detailed work or
of course, you can use an external adjacent editor there isn't that Jason is very important in node
red is because no direct, as you know, is built on node.
Yes.
Which is a JavaScript framework.
And Jason is fundamental in the JavaScript world.
It is an important standard for data interchange and for data storage.
So in particular, for example, you work with Iot services.
It is likely that those Iot services will be using Jason to receive and sent data.
So it is good to have basic working understanding of Jason.
So to demonstrate how to play around with Jason in notes, starting with this example Jason document.
So from here.
You can.
Send it off to the bug window to see what it looks like.
I'm going to enable this note here.
And deploy my new flu or my updated flu and then trigger to inject note, and this is the simplest thing
you can do.
You can see now that the Jason document is part of the payload.
It is inside payload.
And you can actually see its various notes here.
You can see the data in the Jason document.
From inside the debug window, you can not just see the chasten document that is part of the payload,
but also copy, it's part of any part of the document that you want to work with.
For example, I can use this copy path function.
Now, the path is in a clipboard and I can paste that in a text editor or it can see that later.
You can also use this path if you want to process the data and document itself and give you an example
in a moment.
So this kind of browser is very useful.
Let's move on to the next.
Example, I'm going to disable the adjacent payload node and enable the next one here, which is the
adjacent payload right now I'm using the message payload output, but the Jason expression output and
let's see what this does can clean up and deploy and trigger.
So now we have the actual object printed out into the.
Dipak Winter.
So this is not the full payload object, but just the Jason object itself.
Now, this is good, but still not very useful, let's say, for example, that you wanted to extract
a particular value, it could be the added value for this lost entry object or it could be the abbreviated
attribute or brief attribute that you see here.
How do you do that?
Well, there's a few ways to do that.
Probably the easiest, in my opinion, is to use a little bit of JavaScript, because remember that
Jason and JavaScript were very closely related.
So let's try this out.
I will disable this node and then enable these two nodes go to the information window and enable these
two.
All right.
So what I've got here is a Jason node.
You can find a Jason node in your toolbox on the side and it looks like this.
Now, what I've shown you so far is interesting.
It does give us an idea of how the message object and its payload works.
But if we want to focus specifically on Jason, we'd like to be able to do something more useful with
it.
For example, we'd like to be able to extract a specific item out of the Jason or a specific value out
of the Jason document and show it.
So I'm going to show you the last example that I've prepared for you here, which is composed by these
three nodes.
Remember that Jason and JavaScript are very closely related.
So the easiest way to extract data out of a Jason document is to use a bit of JavaScript.
And of course, there are other ways to do this that you can learn about in the documentation.
So here's an example.
I've got a function node and he can access a function node through the site toolbar and there is a function
or it can just drop it on to your flow.
So inside the function node, you can write a bit of JavaScript.
I remember that the function receives a message that could paint a payload just like any other node
does, and you can access the payload using the images DOD payload notation.
But because this payload contains Jason adjacent document, we can then use further dot notation to
access the individual values and attributes of the Jason document.
So let's say I'm just going to cancel that for a second.
I'm going to show you my chasten document and you can see that down here we've got access to the documentation,
which I have copied in the chasten document itself.
Looks like this.
So let's say that I would like to get the value of the title attribute.
Then what we do is to say Jason document, Daudt Glossary DOT title, and that will return, for example,
glossary.
It can do the same thing elsewhere.
And I also remind you let me show you, I'm going to enable this document here.
This note here should say.
I could also have enabled the other one down the bottom, but it's OK.
So going to the Dipak window and I'm going to trigger this and look at the adjacent payload debug node
output, which is this one.
Here we have the adjacent object.
We can drill down to it, but I just wanted to remind you that you can copy the path of the tribute
that we want to extract the value of by clicking on this copy path button or whichever one it is.
And then we can paste that into our Jason right here to complete the the expression for the attribute
that we want to extract from the chase and document.
So in this case, I have configured my function node to have two outputs and that allows it to have
two outputs visually produced in the note itself.
And then I can connect each of those outputs to a different debug node for those outputs.
I want to pass on to data items.
The first one is a title which I can retrieve with a notation like this, and the second one is the
acronym which again I can retrieve from the Jackson document like this.
And then in my return statement, I've got an array.
And in the array of two tiny Jason documents, both have got a payload and then whatever it is that
I want to pass, which is the title, and for the second one is the acronym.
So with that done, I can then just go.
Pass that information to a debug mode like this.
This one is for the title because this it's the first one and this one is the acronym because it's the
second one.
All right, deploy.
Just to disable the first pilot, just to keep my output clean and deploy, clean the back window and
trigger, and that is your example glossary and then the general values printed out, that's a simple
way to extract the values I want out of adjacent document.
That's actually enough to allow us to continue with the project.
But as I said, there's a lot more that you can do with messages.
And I encourage you to have our at least our quick look at this documentation page to learn more about
it.
Now, in the next lecture, I'm going to talk about firewalls and how you can use variables to also
pass information between.