Communicating MQTT Client in Node-RED with Broker

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] okay now let's begin with our first project mqtt basics so in this project we're gonna see how to share the data between mqtt broker and the clients so if you notice here carefully mqtt broker is installed in node-red so i'm going to use my computer in which i have installed my node grid so i'm going to use the system and then you will see we have mqtt client it's also a node-red application so this we will see inside the node-red itself and we're going to see mqtt client and mobile application so i'm going to use my mobile phone just here and i'm going to install mqtt app in this one and i'm going to show you which app is working and how to configure this app to read the value from the broker i can also use my iphone so i can show you the apps in both the phones besides that i can also show you how to read the mqtt client in the windows application which is called mqtt box so we'll see all the possibility to read the information in the computer or in the mobile applications so various steps are included in this project first step is you have to install mqtt box in your computer and that you can do from the microsoft website so i will give you this presentation or put the link in the description and you can see this app you can install from the microsoft website okay so it's very easy just click on get and it will be installed in your computer this is the step one you need mqtt box this is a this is here empty decline so you need a client to read the information secondly if you want to use your mobile phone you can use mqtt dash this is for android phone so if i click on this link you will be redirected to this app so you can use this app to read the information from the broker so again this is a client all right third client i've mentioned mqtt tools for mobile phone if you have ios system so in this case the app kind of looked like this so i have these apps installed in my phone i have this app also installed in my computer so make sure you install these apps once you do that you have to open your node red and you have to install mqtt broker which is this one ads i don't know how to pronounce this itis or so you need to install this nodes in your node red so if you are doing this course i assume you already know node-red because i have already explained that no red is required to understand this course so what we do is i start my node red already i've started this from my command prompt i'm going to show you about this project how does it work well i'm going to explain and then i'm telling you how to do this project yourself okay so i can also show you the code in the end of the section so let's see after installing the apps what is this first step you have to open your node red so here i have my node red opened here okay i will come to these nodes but first we have to install broker so i told you we have a broker inside and how this come here you will not find it here unless you install the nodes so go here in your manage palette click on install and just type aed s and you will find this node-red mqtt broker so just click on install and once you install you will find this in your notes okay so you have this broker i bring this broker here and when i go inside this broker what do you see some boards okay now what is this board so if you remember when i talked about mqtt in the last lecture we have a broker now broker has an ip address so in my case my broker is installed in my computer okay and this computer has an ip address but besides an ip address you always need a port for communication so for mqtt we define the port by default one eight eight three so this will be inside automatically if it's not just type 183 so this is the port we defined for our broker so let me just go back to the diagram and i can explain you one more time you know another simple way so i have my in this project one so i'm using my broker it's a bit not easy to write in the writing part so please excuse my and writing this broker has an ip address which we need to know because when clients are going to connect this broker needs an ip address okay and it needs a port so the ip address how do you know what's the ip address so let's say you bring the broker here and then you put inside 1883 click this ws bind to the port and in the security you can define your username and password so that your broker is secure for connection so here we need four things ipaddress port username and password now ip address will be will be the ip address where broker is installed in my case my broker is installed in my computer okay so what is the ip address for my computer i can find it out by going to command prompt in case if you don't know just type ip config press enter and here you will see the ip addresses 192.168.0.71 this is very important we need to know that when we are going to make connections so it's 192 0.168.0.71 and the port is 1883 and username i have already defined it's node read it's totally up to you what you want as username password is code and compile so you can define your username and password whatever you want so these are the four things you need to connect to the broker okay so i can tell you where i have defined that ipaddress is not defined in this broker node this will be defined in the mqtt client because when the broker is installed in this computer it's by default that broker takes the ip address of this computer okay and board is here 1883 like i've mentioned here username and password it's coming in the security so put your username put your password if you don't want you can also skip the step but if you want your mqtt to be secure do that step as well click on done and once you do that you see here one f i have one connection connected and this connection is because i'm using node red inside node red client inside the node red like i've explained you here we're using one of the client inside the node red and that is one which is connected how it is connected now what you have to do is you have to use this node and this you can find it here very easily mqtd out and this is by default in node red so once you take this node this is the same node so you open that and then you define a topic so in this case my topic is test okay because i have to publish some information in my broker let's go back here so i have this is my broker now we talk about clients so my first client which is my node-red and my broker is also in node-red okay so node red is sending the information as a client to the broker results to note red so in this case this client when client is sending some value to the broker i told you the client is here my publisher and to send the value the client needs what it needs a topic so i use the topic as test we have understood in the last lecture this is my topic so this test i have defined in my note read here this is my topic what is qos we will understand that later so i put it at zero by default and server now server means where should the client publish the value so in this case this broker is my server broker is my server and this is my client so i need my server details that's what i did in my note right so here you can see i click on this pencil icon in your case maybe it's like add new mqtt broker click on that and then you will have a window like this now this is the server ip address that's what i told you you need the ip address of your broker which is installed in my computer so my computer ip address 192.168.0.71 that you mentioned here and you mentioned the port address 1883 this is the same of over empty broker username and password i define here in security i define username and password and besides that i give a name to my client so this you can define by yourself if not it will automatically create it but i want to define it because i want to read which client has been connected so i write note read underscore desktop you can use any name you want so in this case my broker will take the name so now i have a name for my client and that name of that line is note red underscore desktop okay so this is my first client this is my client one which is publishing a topic test that's the client name using the broker communication details and now what is the value being published i just click update because there's no changes or i can just click cancel now the value which is being published is this timestamp it's just basic value payload is a string and that is says hello okay that is the message which i'm publishing in the broker by this node okay i will delete this one so this is the node to read what is published okay so i published hello to my broker so if i show you again this i have published hello which was my message so here i can write my message was hello and this is recognized by the topic test and node-red is publishing the value and i told you in the beginning clients can be publisher or can be subscriber okay so i publish and i can also subscribe so now i publish this value i can also subscribe to this value and this i need to do to subscribe to the value what i need from the broker i just need the topic name test that's it and of course the broker details so when i subscribe this is how i'm subscribing so just to make it clear i can write some comments so this is reading or subscribing prefer to write subscribing and the upper one is publishing so this is publishing forget about that we'll come to that later deploy so now so you can see that when i publish the value hello now this value goes inside the broker here i'm also subscribing to the value and if i open the payload now if i publish again i'm reading the value again which gives you me the value hello okay so if i change this value i write mqtt click done deploy and if i send the value now mqtt to the same topic named test i get mqtt this is coming from here now let's take a very quick example i change the topic to test test one done and this is again test one and i take another topic i rename that to test2 okay and i take another message and here i write code and compile okay also a string and i subscribe publish that to now test tools now we have two topics so i deploy and now both are connected now because i only subscribe to test one i will only get the message mq reading i will not get this message because i'm not subscribing to it so if i subscribe to another message let's say test 2 and deploy now i will get another message so the subscribing can be anywhere it can be inside the same computer or it can be in a mobile application okay so we have seen publishing and subscribing via mqtt client which is publishing and subscribing as well in the next videos video is getting longer i will show you how to do that using a mobile application all right let's see that in the next video how to publish and subscribe using mobile application thank you for watching ciao you
Info
Channel: Rajvir Singh
Views: 5,278
Rating: undefined out of 5
Keywords: mqtt, what is mqtt, mqtt projects, iiot, iot, mqtt iiot, mqtt iot, mqtt with plc, link mqtt with plc, send message via mqtt to plc, mqtt message to plc, plc and mqtt, link plc to mqtt, connect plc to mqtt, mqtt communicate with plc, mqtt course, mqtt lessons, mqtt tutorials, codeandcompile
Id: LSygMNelyr0
Channel Id: undefined
Length: 15min 14sec (914 seconds)
Published: Fri Apr 23 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.