Training Index: https://fusion-automate.super.site/1f38090ec617464884074d74a9561856
------------------------------------------------------------
Website: https://fusionautomate.in
Telegram: https://t.me/fusion_automate_admin
WhatsApp: https://wa.me/message/B7RXUT4OUXWUF1
Instagram: https://instagram.com/fusion_automate
LinkedIn: https://www.linkedin.com/company/fusion-automate
GitHub: https://github.com/papercodeIN
Join this channel to get access to perks: https://www.youtube.com/channel/UCKKhdFV0q8CV5vWUDfiDfTw/join
------------------------------------------------------------
------------------------------------------------------------
Website: https://fusionautomate.in
Telegram: https://t.me/fusion_automate_admin
WhatsApp: https://wa.me/message/B7RXUT4OUXWUF1
Instagram: https://instagram.com/fusion_automate
LinkedIn: https://www.linkedin.com/company/fusion-automate
GitHub: https://github.com/papercodeIN
Join this channel to get access to perks: https://www.youtube.com/channel/UCKKhdFV0q8CV5vWUDfiDfTw/join
------------------------------------------------------------
Category
🤖
TechTranscript
00:00Hi, everyone, and welcome. In the previous video, we have covered ESP 32 as an MQTT broker,
00:09and we have used Pico MQTT library to convert our ESP 32 into the MQTT broker. So instead
00:15of Hive MQTT broker, Mosquito MQTT broker or Nano MQTT broker or any other cloud MQTT
00:22broker, you can use your ESP 32 board as an MQTT broker for your small scale application.
00:28But in that video, in that code, we have used port 1883, which is the default port
00:35for MQTT broker. Okay, but for some security reason, if you don't want to keep the default
00:41port 1883 for TCP communication or MQTT broker, then how you can change it in the Pico MQTT
00:47library. So that thing we are going to cover in this video. So basically, we will see how
00:52to set up basic MQTT broker with a custom port, okay, custom TCP port in ESP 32 using
00:58Pico MQTT library. So again, we are going to set up MQTT broker in the ESP 32 board.
01:04But instead of the port 1883, which is the default, we are going to select some other
01:08TCP port for MQTT communication. Okay, so let's see how you can do that. And here is
01:15the communication diagrams. So our ESP 32 board is in the center, which act as an MQTT
01:20broker for all of the client, and all of the client can publish to any topic, okay, and
01:25all of the client can subscribe to any topic, and they can exchange the data and everything
01:30will happen in the local area network communication. Okay, so your ESP 32 will connect with the
01:35Wi Fi, your ESP 32 c three or Python MQTT client also connect with the Wi Fi and they
01:40can publish and subscribe the messages. So instead of port 1883, we want to start our
01:46MQTT broker with some different ports. So let's see how you can do that. So here is
01:51the Arduino ID. Okay, I have already installed Pico MQTT library in my Arduino ID, you can
01:58see Pico MQTT is already installed. Now we will go to the examples and here we will search
02:04for the Pico MQTT folder. Okay, here you can see Pico MQTT. And here you can see the example
02:11server with custom port. So we are going to select this example. When you load this example
02:17into the ESP 32 board, your ESP 32 board will act as an MQTT broker, but it will run
02:23your MQTT broker on custom MQTT port. Okay, here you can see. So whatever TCP port you
02:30define here, your MQTT broker will run on that TCP port. Okay, so first of all, you
02:36have to provide your Wi Fi SSID here. So my Wi Fi SSID is and here we have to provide
02:43the password for your Wi Fi. And then after on whatever TCP port you want to start your
02:50MQTT broker, you can specify that in this line. So instead of port 1883, if you want
02:57to start your MQTT broker on the port 9000, then you can specify the port 9000 here. So
03:03your client has to use the port 9000 to connect with your ESP 32 MQTT broker, they cannot
03:10use port 1883 to connect with this MQTT broker. Okay, and rest of the code is same as the
03:15previous video. So it will connect with the Wi Fi. Okay, and then it will continuously
03:20run our broker. So I'm going to upload this sketch into our ESP 32 board. Okay, so I'm
03:27going to hit the upload button. Okay, here you can see done uploading. Now we can open
03:46serial monitor to find the IP address of our ESP 32 board. So I'm going to press reset
03:52button on my ESP 32. And here you can see connecting to Wi Fi. And here we have the
03:57IP address of our ESP 32 board. Now, in the previous video, also we have the same IP address
04:03of our ESP 32. But the port number was 1883. Now we have a different port number for MQTT
04:10communication. So let's open the MQTT client and let's connect with our ESP 32 MQTT broker.
04:17So I'm going to open MQTT Explorer here. And here you can see in the previous video,
04:24we have used port 1883 to connect with our ESP 32 broker. But if I try to connect then
04:29it won't able to connect because the MQTT broker is running on port 9000. So I have
04:35to abort it. And then I have to change the port number to 9000. And then I can connect
04:40it. Okay, here you can see we are connected. So if I use port 1883 then it won't let us
04:50connect Okay, it will always stay in the connection mode. Okay, it will try to connect but MQTT
04:58broker or ESP 32 won't respond to that connection request because of different port. So we have
05:03to change the port number to 9000. We have to abort it and then we have to connect again.
05:07And here you can see we are connected. I can again open one more MQTT Explorer client.
05:13Okay, and I can change the port number to 9000. And I can click on connect to connect
05:19with our ESP 32 MQTT broker on the different TCP port. Now the different TCP port is sometimes
05:25required due to firewall issues or some security reasons. Okay, so if we keep the port 1883
05:32as a default, then anyone can get access to our ESP 32 MQTT broker. And if we change
05:37the port, okay, instead of 9000 or 1883, if we change the port to something else, okay,
05:43as per our requirement, and as per our firewall rules, then no one can connect with that ESP
05:4832 MQTT broker. So that's why custom TCP port is required. Now I can publish some data to
05:54the test topic. Okay, the data is 123. And here we are going to receive the data. And
06:00also I can publish the data from here 456. And that I'm going to receive it here. Okay,
06:06so our MQTT broker running inside the ESP 32 is working fine. Our two different client
06:12can exchange the data with each other. So this client is also publishing and subscribing
06:18to the test topic. And this client also is publishing and subscribing to the same topic.
06:23So this is how you can use your ESP 32 as an MQTT broker with a custom port. Okay, or
06:28you can say custom TCP port for your MQTT broker communication. So I hope this thing
06:34is clear that how to set up basic MQTT broker with custom TCP port in ESP 32 using Pico
06:40MQTT library. If you still have any questions or any doubt, then you can always ping me
06:44on Telegram, Instagram, WhatsApp anywhere. All the social media link is available here
06:49on our website. So let's meet in the future videos. And in the next video, we will see
06:53how to set up secure MQTT broker in the ESP 32 using Pico MQTT library. So right now,
07:00whenever you try to connect with your ESP 32 broker, it won't ask for any username and
07:04password. Okay, you can see username and password field is empty. So if you want to set up the
07:10username and password, okay, if you want to make your ESP 32 broker secure, then how we
07:15can do that. So that thing we are going to cover in the next video. Okay, so stay tuned
07:19for the next video. Till then, take care. Goodbye. And thank you