Simple Node-RED and MQTT Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey there and welcome to my studio I'm gonna go over this quick example on how to receive data and publish data using the MQTT nodes within node-red so this example I've outlined in the tutorial but I'm gonna just show you quickly here because sometimes people are visual learners and it's easier to just watch somebody do something and you'll get it no problem alright so I have 4 terminal windows open the first ones running mosquito the second one is running node red the third one has the SUBSCRIBE command for mosquito and then the fourth one has the publishing command for mosquito then I also have my Chrome browser open with node red you can see node red is on one 2700 dot one that's port 1880 and then I've just put in a couple comments here in this flow I've got to subscribe to topic comment and a published a topic comment and I'm going to go over both of those scenarios right now so we're going to go ahead and grab ourselves an mqtt node and we'll drag that over and then we're also going to grab ourselves a debug output node and drag that also over and we'll connect the two together and then we'll double click on the MQTT node and we're going to use our local host port 1883 as the server and so to access this you're going to click on the pencil and you're going to just type in localhost for 1883 and then the rest of the settings will be default so that's what I have and then the topic we're using today is called topic /hello and so I'm going to name this node subscribe and we'll go ahead and click done and that looks good so what we'll do is we'll hit deploy and it's really just that simple so if everything is working correctly you'll see that underneath subscribe it'll stay connected and we'll go ahead and we'll open up our publishing terminal window and we're going to send it we're gonna send the topic hello topic the message hello world so I'm just gonna hit enter and you'll see that it shows up here inside of my debug window saying that we received this message so that's really as simple as it is now we've got mosquito communicating to node-red and so that means when we go ahead and we connect up are we most d1 many we can send information using mosquito and receive it inside of node-red so the other side to that is being able to send information through mosquito to something that's subscribed to it so we want to be able to publish a message so what we'll do is we're going to bring down an input inject node and then we're also going to bring down our MQTT output node we'll connect those together and rather than sending in a timestamp we're going to send it in a string so if you just double click on timestamp go up to payload and then choose strength we can send it hello world and I'm just gonna put it inside parentheses node red to show you that we're sending this message from node red and the topic that we want to send this message on is called topic hello and then I'm going to give the name publish and so that's pretty much all you need to fill out you can click done and then for the MQTT node we're gonna go and make sure you choose your localhost 1883 server the topic is gonna be topic hello and this topic name can be whatever you want so you can call this topic name my special topic so long as you're publishing messages or you're receiving messages on my special topic so whatever you want to call this you can call it whatever you want just make sure you're consistent or you won't be receiving data and so then I'm just going to call this publish and so now we've got our message that's going to be published to our publishing mqtt node so we'll go ahead and we'll deploy this you'll see also that we're connected here on the publishing side so when I go ahead and I click the inject what will happen is we should see inside the debug window hello world node red and then if I go ahead over in my terminal and I subscribed to that topic we should also see it appear here so we'll go ahead and we'll inject this node and you'll see that our hypothesis was correct we now see hello world inside of our debug tab and we also see it in the terminal window where we're subscribed to topic hello and that's pretty much it we've now established bidirectional communication using node read and mosquito which is our MQTT broker I hope this little mini demonstration was helpful and continue scrolling through the rest of this article so that we can get our dashboard setup working with the we most d1 mini until next time my name is liz with learn robotics and i hope to see you soon
Info
Channel: Learn Robotics
Views: 56,294
Rating: undefined out of 5
Keywords: robotics, electronics, programming, tutorial, Learn Robotics, mqtt, node-RED, mosquitto, IoT, dashboard
Id: LXA-Ge3-ewo
Channel Id: undefined
Length: 5min 39sec (339 seconds)
Published: Tue Jul 24 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.