Category
🤖
TechTranscript
00:00Hi everyone and welcome. In this video we will see how to use your ESP 32 board
00:07as MQTT broker. Okay so yes we can use our ESP 32 board as MQTT broker. So
00:15instead of Hive MQTT broker, Mosquito MQTT broker, Nano MQTT broker or
00:22any other cloud MQTT broker you can directly use this ESP 32 board as MQTT
00:27broker. So you don't need to install Mosquito MQTT broker in the Raspberry Pi.
00:32You don't have to purchase any other cloud broker services for communication.
00:36You can use your ESP 32 as a cheapest MQTT broker. Okay and with the help of
00:43these three library you can perform that action. So the first one is Pico MQTT. The
00:48second one is Embedded MQTT broker and the third one is S-MQTT broker. So now in
00:53this video we are going to cover the first topic. Okay how to set up basic
00:58MQTT broker in the ESP 32 board using Pico MQTT library. Okay so let's see how
01:05you can do that and before that here is the diagram. So we have our ESP 32 board
01:11in the center which work as the MQTT broker and here is our MQTT client and
01:16you can exchange the data between each of your client and this is diagram for
01:21the local area networks. So once you deploy your ESP 32 board as MQTT broker
01:25in the local area network your n number of client in the local area network can
01:30connect with this ESP 32 MQTT broker and they can exchange the data. Also you can
01:34do the port forwarding of your ESP 32 MQTT broker and then after you can
01:39access your ESP 32 MQTT broker from anywhere in the world over the internet.
01:44So that is also possible but you have to do some port forwarding stuff for that
01:48but in the local area it will work absolutely fine without any problem. So
01:53let's see how you can load the code and how you can use it. So here I have
01:58already installed the Pico MQTT library in my Arduino IDE. So here you can see
02:02Pico MQTT which is already installed and I'm going to the examples. Okay here in
02:09the example you will have to find Pico MQTT folder as you can see Pico MQTT
02:14and we are going to select the basic server example. Okay so here is the basic
02:20server example or you can say basic MQTT broker example for ESP 32 board. So
02:25first of all what will happen your ESP 32 board will connect with Wi-Fi. Okay
02:30for your local area network communication and then after your Python
02:34client your ESP 32 C3 or any other NodeMCU board will connect with this ESP 32
02:40MQTT broker. So first of all we have to make ESP 32 available in the local area
02:44network by connecting to the Wi-Fi. So here I'm going to provide the SSID which
02:50is and here is the password. Okay and that's it. So in this example all you
02:58have to do is you just have to change the SSID and you just have to change
03:02your Wi-Fi password. So ESP 32 board will connect with your Wi-Fi and then after it
03:07will act as a MQTT broker. Okay now we can select our board. Okay and we can
03:13select the COM port. That's it. We can directly upload the code in our ESP 32
03:17board.
03:31Okay so you can see done uploading. So we have successfully uploaded this code into
03:36our ESP 32 board. Now I'm going to open the serial monitor here and I'm going to
03:41press the reset button in my ESP 32 board. You can see connecting to Wi-Fi.
03:47Wi-Fi connected and here is the IP address. Okay so this is the IP address
03:52which we are going to use to connect with our MQTT broker. Now I am going to
03:57open the MQTT Explorer software which is our MQTT client. Okay so you can use any
04:04MQTT client software. It can be your Node-RED. It can be your SCADA system. It
04:07can be your test MQTT client anything. Okay all of your MQTT client will
04:13connect with this ESP 32 MQTT broker and right now in this code the default port
04:18for communication is 1883. Okay you can change this port number as well in this
04:24code but that we are going to see in the future videos. Now here we have the IP
04:28address 192.168.1.11. So I'm going to copy this and I'm going to add new
04:33connection which is my ESP 32. I'm going to provide the IP address of my
04:38ESP 32 here and here is the port number 1883 which is default for this basic
04:44server code. Okay and I'm going to click on the connect and here you can see we
04:49are connected. Also let me open another MQTT Explorer. Okay and again we will
04:57add new connection which is ESP 32 and I'm going to provide the IP address of
05:02my ESP 32 and I'm going to save it and then I'm going to click on connect. So
05:07you can see both of the client is connected with my ESP 32 broker and also
05:12I can publish the data. So I'm going to publish the data on the test topic and
05:16I'm going to publish 111 and here you will receive that. Okay and on the same
05:21topic I can publish another value. Okay and you will see the update in both of
05:27the clients. Also we can try for one more value and here you can see. So what
05:33exactly happening is we have two clients. Okay so this is the first client and
05:38this is the second client. So both are connected to our ESP 32 MQTT broker and
05:42both are exchanging the data. Okay so this is how you can use ESP 32 as the
05:47MQTT broker and this is the basic code. Okay we haven't secured our MQTT broker
05:53with the password as well and we haven't configured custom port but that thing we
05:58are going to see in the future videos. Okay so custom port configuration and
06:02username and password configuration is only available with the Pico MQTT
06:06library. Okay so those are limitation for other libraries. So if you are going to
06:10use the embedded MQTT broker then you cannot set up security in that broker.
06:14Also the same case with the S-MQTT broker and there are some other
06:18limitation as well. So I'm going to provide the GitHub repository link for
06:22all these three library and there you can view the limitation of this brokers.
06:27Okay but for normal use case it will work fine. Okay here and here you can see
06:33both clients are connected. If I remove my ESP 32 from my system okay and then
06:41after we were not able to publish any data. So if I publish data to 4444 on the
06:46topic test then we are not able to publish it. Okay and if we disconnect and
06:52if we try to connect then we are not able to connect. So let me again connect
06:56my ESP 32 with my system.
07:02You can see Wi-Fi connected and here you can see it is connected. Okay let me
07:10connect this client again. Okay and we can publish the data and that is
07:14available here. So it is working absolutely fine with ESP 32 board. Okay
07:20so I hope everything is clear that how you can use ESP 32 board as MQTT
07:24broker using Pico MQTT library and the code you can get the code from example
07:31only. So you have to go to the example you have to search for the Pico MQTT and
07:35you can use this basic server example. Okay so I hope everything is clear and
07:42if you still have any questions or any doubt in this then you can always ping
07:46me on Telegram Instagram WhatsApp anywhere. All social media link is
07:49available on our website. So let's meet in the next video and in the next video
07:54we are going to cover this topic that how you can set the custom port for your
07:58ESP 32 MQTT broker. So let's meet in the next video. Till then take care goodbye
08:05and thank you.