Hey guys, this is Cristiano from Crescer Automation Industry, who has already watched a lot of our videos, it's not written on the channel, take advantage, now sign up today, here's the thing, we're going to have an academic week where we're going to speak here at PUC from Rio Grande do Sul and I'm preparing some IoT internet of things material And then I'm drawing here and I want to share with you something very interesting here related to mqtt, it's a protocol that is practically being used as a standard as it is internet of things and I discovered a lot of interesting things here, a lot of cool things that I want to share in this video here with you, I'm drawing here the topology that I'm going to take there in this presentation and I believe it's a topology that's very useful too, because there are some elements of mqtt and I'll even recommend a video for you that gives a basic explanation, not that it's basic but a very interesting base of mqtt, which is this video here, it's from EngEasier What is mqtt, so you can give it Take a look there and there's a very interesting base before you can see it here or preferably next, you can see it Wow, this is our application But here's the thing, what do I have here that is interesting, which is a differentiator from these videos what we are doing what we are looking at we have the broker locally What does this mean for mqtt to work it needs a Central entity which is normally called mqtt broker which would be a server for this message exchange ok mqtt is a standard for exchanging messages, so let me get it here, this text here, Message Queuing Telemetry Transport, that's it, I even got some, I want to discuss it in the lecture, right, telemetry, which was a measurement, tele means something remote, something distant, so a remote measurement, a measurement distant then How to transport this data and Queuing is queuing So queuing these messages is to arrive and manage within our server which is this guy here who I think normally needed it not a while ago when I studied I needed one from a PC from a computer or even a Raspberry which would be a mini PC there running this mqtt server and now I'm going to show you a library that makes it possible to transform an ESP32 into an mqtt server so broker server the cluster is the guy who centralizes what he centralizes another interesting term, the topics, the topics would be the internal addresses of the messages because what happens then the server is the only guy, the only entity that will have a fixed address, be it an address in the cloud, right, if it is hosted in the cloud, be it a Fixed IP locally but it needs to have a fixed address so that all clients, all devices that are around this server can find it, so what will I have in this tool that I will share with you in addition to the Server broker in ESP, just so you can see here, then I'll show you the test, I have this topology set up here, but I need to explain it because otherwise it won't be possible to understand much, so let's go broker, what's another very interesting point when developing a project with mtt ? It's this entity here, I'm going to show you this mqtt explorer that you 're going to download a website, not download a website, not download a program, you're going to run it and what it's going to do, it's going to basically mirror what's happening inside the Server so you will be able to see all the clients who are posting messages or who are signing up to read messages, okay, you go with this guy here, you can once you install him to connect, let me see, I'll connect here, just one Once you install it and there is an mqtt server on this IP here, I will show you how you use this software, you will be able to see what is happening inside this server, so it is very important that this tool here will show you, I will already show you the video. right from EngEasier, you can find the name there, look for it and here is the mqtt-explorer.
com website, you can come to this website here and download it . with you and you run it and this little program will open here, let me disconnect it, it opens on this screen here where you will configure here where the mqtt server is, it even comes with the port mentioned here so that's it, so what I've already detailed here I've already detailed the viewer, right, which is the mqtt explorer, you're calling it viewer because it's visualizing who these are entities that are around the mqtt broker are clients are clients and what do they do in this topology in this communication protocol they can publish information so if it is just a sensor that is selling temperature sending data it only publicizes it publishes data there on the server or it can be a subscriber where it requests data where it goes and looks for some information on the broker there on the server so I 'm going to be in that moment now from this video I'm going to have a normal ESP32, it's plugged in here on mine machine I'm going to show you what I want to show the libraries which library has the broker and which library has the clients, the subscriber and the publisher and I'm going to have a CPB as well, I have a CPB here in my video, okay? with a CPB it touched this here is the other Client and here is the broker including it is running when I go when I install this software I will operate this software here let it run when I install this software which is important you can create a new connection I even recommend it here so as not to always have a model saved here, you can even monitor Brokers in the cloud, ok, just have access to this host name and you can be monitoring this broker, so I saved a location here, I put an IP and on this one which is the server I left the IP fixed or go through the code to do this and here is the port that normally runs mqtt connect what happens it detected that there really is an mqtt server there and there are already messages arriving here There 's a message arriving here, since I opened it, 6 messages have arrived in a thread, that's the address OK, so let's go, let's go, let's go, let's start Here, let me see what else is important, here, let me go back here to my script, there's a script here topology I'm presenting mqtt Viewer I presented So let's create the broker now first thing let's create the broker which library you will be using you will download this one here o smqtt broker So when you download this library you will have some examples here Let me get to it you can even download it right here sketch include library in the library manager if you put it there smqtt broker you will find it ok let me close it here now it will take a little while cancel cancel close because as I set up a topology here where I am using it I want to put it here so you guys, I'm using this one, I'm going to take a router to the presentation, a mini router here, right ?
Just as a device, I even recommend it for projects, don't always depend on the ESP whether or not it has the power to reach a network, always keep setting up a local network since these rare ones here are very cheap, right? I'll come back here to close, so this is the library, what I have here, I have my logic here, you will open Simple broker Simple broker, calmly, what I did to create a fixed IP is so that all clients can see this address here I put these IP variables here, where do you find this address? If you need the source code, it's important to look at other videos that explain some of the basics, but here, for those who already know the ESP32, this part here, about the wi-fi, is here oh where do I get this code here oh the wi-fi Client static IP is there you will get this this logic here of creating variables of type IPaddress let's see here and make this configuration this here fixes the IP that config There will fix the IP , this here is the wi-fi network made by the router there that the ESP broker is connecting to and here it started the broker and basically it is doing what I understood as critical here at nos Brokers and it is something that when you If you're doing a professional project, it's important to pay attention, I'm going to open a serial monitor, that's how much frog it takes up from what I understand.
that the more topics and it's the opposite but it will take up So you have to take care of this when creating a project which will probably be the limit of using an ESP 32 as a broker precisely in the amount of RAM So I don't know what a suggestion leave at least 50 k Always Free, right Unless it starts to crash before the ESP, right, but I think up to 50 k is fine depending on other things, well, just use it as a broker, right, so let's go, monitoring RAM memory, we have ours here broker I already said what the library is, I showed something well that maybe I don't understand here, as in the presentation I don't want to keep connecting the cable to the equipment, I added the ota code here which is to make the charge over to the air in Over The air in ESPs they appear here for me, they appear on their IPs, I already changed the name, so, if I want to load my code without using a USB cable, I can load it on this IP here, broker 32, so I already know that I'm both on the same network I don't need a cable to load the firmware so I like to be using this ota here Let me see if I finished where can you get the example of the act So let's go in case anyone sees me some type here Arduino basicOta here Can you get the example of the other including loading signature with the firm in the cloud not so much in the same place in the same place, I've finished this library here now we create one when you create it to load ESP automatically it will already be viewable in mqtt explorer it already has the server here like me I already have the CPB32 publishing data, look here outopic/CPB, I'm going to put it in now and I'm going to film it for you. Let me show you here. I'm going to put my other hardware, another ESP Client, which is sending commands to CPB.
I'm going to connect it to my PC, which is this hardware here, and when I connect it, let me show you, notice that it will change here, in mqtt explorer because this guy will start sending it, he will start making publications for the other one to another CPB and CPB will read it so what happens this ESP that I connected here he makes a post in this topic intopic_CPB ok so this guy here let's go makes a post in that thread there eintopic_CPB and CPB makes a subscribe to that same thread This is what causes this interaction between them, one is publishing and the other is subscribing, which is being a client of that topic, reading that topic and this is what is doing this data exchange, here we will now show which library I used, okay, and you will see what's happening inside it? So, I'm going to take a look here, what I was talking about is the library that you have to use to set up the clients, which I found very interesting, this one here, PubSubClient. library here is not for I don't need to put the fixed IP this makes all the difference in a professional equipment the only thing I need to give this in all installations I need to give the address of the server be it local like here or in the cloud I need to give the address So here it is in this period and what am I doing here?
OK, I'm Let me get there I'm doing a get there in the topic I'm using the same one I'm doing the following, now I'm writing 0, Time I'm writing 1 okay let me see oh no sorry 0 no time I'm writing this here in the topic time I'm writing this other one here why isn't it changing now because I disconnected my internet cable here I'm going to connect it again now And then the mqtt explorer is not working, now I'm going to connect it, it will start working, okay, in a little while it will start to see the data again, here wait a little while if it doesn't connect it again, it won't let me go out and connect again, connect It's here, so, note there, it changes , every time you hear the relay clicking, it's sending a new message here Ok, so what 's happening, this one, I'm going to disconnect now so as not to lose the video, this client of mine, where is it? he is right now here making a publication in my thread there, look here, it is well reflected here in the code that is happening in the explorer, in this thread he is writing this here and there in CPB I have a code that when reading this binary sequence here turns the relays on and off Okay, but it's the same logic like this. I have it.
I have it. Let me see where this code is . top and reading every time this message is written Let me see if I forgot anything at first I'm finishing this video this is the information I wanted to be passing on to you so let's take a look back here at my drawing if I passed Anyway, I have an mqtt viewer here and it's always there, why did I put it so that it can publish, look how interesting I turned off the client and look what I'm going to do Look what I'm going to do, this is a lot cool let me just leave everyone together here if I do it quickly the video won't fall Look what I can do I can use this Explorer to publish data let me connect the cable here and let me try to do it I'll get the relay here ok I'm just going to get the relays that are more visual, three so that's not possible, I'm going to connect them with a connector Look, let me increase them a little, so it has to be while the video doesn't go down, I'm connected, okay?
The topic is already here and I'm going to publish it, it's not easy 1 which turns off then there, even without having it here I can publish it too, right 0 0 0 turns on right 1 1 1 turns off then from here that's why in the drawing this Viewer I can either subscribe which is reading all the topics as much as I can send a publish this here to do tests, ok, so this is what I wanted to show you here, ESP, which is one of the clients that also has a dynamic IP, I don't care which IP it gets from the network's DNS network, right?