The Node-Red Message Object for Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
video I want to take a look at the node-red message objects now no anode read flow consisted of series of interconnected or wired nodes and all nodes must have an input and they can have zero or multiple outputs and they exchange data using the message object the message object is passed between between the nodes this is a simple demo flow that I just created to demonstrate the the message object and first I'm going to use the inject node and I'm just basically going to use it to inject a message into the debug node and we can display it in the debug window over here and to make that send a message I just click here and it will send a message into the debug node and I should see it here now what I'm sending here is a timestamp and I can send various things in here numbers strings JSON objects etc but for illustration I'm just going to send this the timestamp in there so let's just click on this and we see the time appear over here now if you can see here it says message dot payload now by default the debug node will display the message dot payload now there are more properties of that message object and if we want to see all of them we just select complete message object and done and deploy it and then when we do it again this time we see the message payload we also see a topic and we also see a message ID so that message itself consists of various various properties the messages as a message object now depending on where the message originated depends on the properties of their object so I've created an mqtt subscribe node here and it's subscribing to a topic house wild card and there's the broker configured there this is not so important all I want to do here is to illustrate the fact that des pet the mqtt node will create a different message object or message object with different properties and we've got that message object going into the debug node and we should see the results over here so all our to do is trigger that mqtt note to send the message and to do that I'm going to use the command line so here we are at the command line now I'm just going to send a pub message on House s1 and it's gonna say test message that's all I'm gonna do and I've cleared the debug node here so we can see it and let's just send the message and you can see over here now that it consists of a topic has sensor one a payload test message quality of service retain flag and message ID so a message object originated here actually contains different properties and the message property the message object originating from this node here and now nodes can actually change the message object and they can create a brand new message object they want to but I'm going to show you how to change the message object as it goes through and to do that we've got a function node so I'm just gonna send the timestamp into a function node and back out again into the debug and let's remove that and clear over here and if we look at the function by default all it does is returns the message object so it shouldn't do anything to the message object it should just go all the way through so if we click on here and you can see it's gone all the way through topic blank message ID and the payload there okay so let's modify our function so it modifies the message object now we can modify the payload we can modify the topic or we can actually create new properties so I'm actually going to do two things I'm going to modify the topic so it has a topic and I'm going to add another property to the message object as it goes through so I've just changed the function so as it adds a topic to it or add something to the topic property because the topic property already exists and I'm going to create a new property and give it the value of new and then I'm just going to return the message and let's see what happens that and deploy it and run it now if we look over here on the right-hand side we can see the topic now is called test topic and we've got another property called a new property and it's got a value of new and that property didn't exist here and that topic was a blank originally so we can use the function know to modify the the message object know with the function note I can actually return multiple message objects and this is useful if you've you've got a split output so you're feeding into several different nodes now if I don't actually return the message object then the flow stops so if I just comment that out and done and deploy it again and this time when I trigger it nothing happens you don't see anything appearing over here and it triggered it again and nothing's happened so basically if you don't return the object the flow stops there nothing comes out of here and goes into that node there okay that's all I really want to say about the message object before we finish the video I just want to show you something you might find a bit useful if you want to copy a flow or parts of a flow you just use the ctrl key and click on the various nodes and then you go to the other part of the canvas here or you can create another flow and then you just do ctrl C to copy it and you see it's copied and then you say click down here I keep right-clicking but that doesn't work and you just ctrl V to paste it and you've got the flow there and say you can create another node sorry another flow again I'm right-clicking I shouldn't do and just ctrl V to copy it there and likewise you can use ctrl a to highlight all of them and I'm just gonna delete all of them with the Delete key cuz I didn't want that anyway so that's the end of the video if you've got to comment then leave it below if you like the video then you can use the like button below and if you want to get notified when I publish new videos then you can subscribe to the channel and if you go over to the website you can also subscribe to the newsletter II if you want to until next time bye
Info
Channel: Steve Cope
Views: 47,702
Rating: undefined out of 5
Keywords: Node_red, msg, object, properties, change, stevesinternetguide, flow, copy
Id: y05vQUIMIxs
Channel Id: undefined
Length: 7min 13sec (433 seconds)
Published: Sat Feb 24 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.