ESP32 as MQTT Broker | How to Setup Secure MQTT Broker in ESP32 using PicoMQTT Library with Username and Password Authentication |

  • 3 weeks ago
Training Index: https://fusion-automate.super.site/1f38090ec617464884074d74a9561856

➡️How to Setup Basic MQTT Broker in ESP32 using PicoMQTT Library: https://youtu.be/tc8zKb6f3TU
➡️How to Setup MQTT Broker with Custom TCP Port in ESP32 using PicoMQTT Library: https://youtu.be/hf7KY0_bu-4
➡️How to Setup Secure MQTT Broker in ESP32 using PicoMQTT Library with Username and Password Authentication: https://youtu.be/iUi_xfFlSug

------------------------------------------------------------
Website: https://fusionautomate.in
Telegram: https://t.me/fusion_automate_admin
Telegram Group: https://t.me/fusionautomate
WhatsApp: https://wa.me/message/B7RXUT4OUXWUF1
WhatsApp Group: https://chat.whatsapp.com/DW7K2yo3ee52mtG4ODTvtc
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

🤖
Tech
Transcript
00:00Hi everyone and welcome in the previous couple of videos we have covered that
00:06how to set up MQTT broker in the ESP 32 board okay so instead of any other MQTT
00:12broker like Mosquito, HiveMQ, EMQX okay or NanoMQ you can use your ESP 32
00:19board as an MQTT broker so we have covered that how to set up basic MQTT
00:23broker in the ESP 32 using Pico MQTT library also we have covered that how to
00:28set up basic MQTT broker with custom TCP port in ESP 32 using Pico MQTT
00:34library now in both of that video our ESP 32 MQTT broker was not secure okay
00:41so we can connect with that ESP 32 broker without any security or you can
00:46say without any username and password so if you want to make your own secure
00:51broker with the ESP 32 then also you can do it with the Pico MQTT library so
00:56that thing we are going to cover in this video so basically we will see how
01:00to set up secure MQTT broker in ESP 32 using Pico MQTT library so until and
01:06unless you provide the username and password then only it will connect
01:10otherwise it won't connect to that MQTT broker so that kind of security is
01:15possible in the ESP 32 MQTT broker so let's see how you can implement it so I
01:21have my ESP 32 board connected with my system and here is the Arduino IDE and
01:27here is the connection diagram so whatever clients you have those are
01:31going to connect with our central ESP 32 MQTT broker and in the previous videos
01:36we don't have any security for this broker so any client can use the IP
01:40address and port number and they can connect with our ESP 32 MQTT broker but
01:44we don't want to do that we want the secure broker so we will implement the
01:49security in the ESP 32 broker in this video okay so let's see how you can do
01:54that so I'm going to the examples in the Arduino IDE okay and we will find the
02:01folder which is Pico MQTT here you can see Pico MQTT and here you have the
02:06example which is server authentication okay so we want to create our MQTT
02:12broker in the ESP 32 with the authentication so I'm going to select
02:16this example
02:18and here is our example so you have to change few things in this example so
02:24first of all you have to change your Wi-Fi SSID so let me change it and then
02:29after you have to change the Wi-Fi password why we have to change the Wi-Fi
02:34SSID and the Wi-Fi password because our ESP 32 is going to connect with the Wi-Fi
02:39okay and our Python client or any other MQTT client is also going to connect
02:43with the same Wi-Fi and in the local area network all those client can
02:47exchange the data with each other and our ESP 32 will act as a MQTT broker in
02:53our local area network so that's why we have to first connect our ESP 32 with
02:57the Wi-Fi and then after in the code here you can see the define username and
03:04the password so they have defined two username in this example the first
03:08username is Alice and the password for that user is secret and the second
03:13username is Bob and the password for that user Bob is password so if you
03:18provide any other username and password apart from this then you won't be able
03:22to connect with our ESP 32 broker so I'm going to leave this things as it is okay
03:27I'm going to leave this username and password as it is and we will directly
03:32upload this code or you can say we will directly upload this sketch into our ESP
03:3632 board so my board is connected on the com file I'm going to hit the upload
03:42button and rest of the things are same as per the previous video so there is no
03:49change in this void setup and the void loop code
03:53you
04:10okay so we have successfully uploaded this sketch into our ESP 32 board now I'm
04:15going to open the serial monitor here and I'm going to press reset button on
04:19my ESP 32 board okay here you can see trying to connect with my Wi-Fi and Wi-Fi
04:25connected and here is the IP address of our ESP 32 MQTT broker now I can open my
04:31MQTT client software which is MQTT Explorer to connect with our ESP 32
04:37MQTT broker and here is the IP address okay 192.168.1.11 and here the broker is
04:45running on the default port okay which is 1883 so we can press on connect okay
04:51you can see connection refused not authorized because we have set up the
04:56username and password in this connection so if you do not provide this username
05:00and password you won't be able to connect with this ESP 32 MQTT broker so
05:05you must have to provide this username and password so I'm going to paste the
05:09username here and I'm going to paste the password here and then we will try to
05:15connect you can see we are connected okay and if you don't provide any
05:20password or if you provide any other password suppose secret 1 2 3 and actual
05:25password is secret then also it won't able to connect bad username and
05:30password okay so let me change the password to the actual and then we will
05:35click on connect so we are connected now let me open another MQTT Explorer client
05:40and here I'm going to use the another username okay which is Bob and I will
05:48use another password which is password for the Bob user and then we will click
05:53on connect and we are connected so here is our both MQTT client okay which is
05:59connected to our ESP 32 broker now I can publish the data on my test topic okay
06:05and both of the user will have those data so both of your client will connect
06:11to that ESP 32 MQTT broker securely with username and password and both of the
06:16client will publish the data to any topic also they can subscribe to any
06:21topic and they can receive the data okay so this is how you can set up your
06:25secure ESP 32 MQTT broker so all you have to do is you just have to go to the
06:31examples okay in the Pico MQTT folder so where is the Pico yeah so here is a
06:38Pico MQTT folder and you have to use this example server authentication and
06:43once you load this example you have to change your Wi-Fi SSID here you have to
06:48provide your Wi-Fi password to connect your ESP 32 with your local area network
06:53and once your ESP 32 will connect with your local area network it will start
06:58serving as MQTT broker okay and here is the username and password to connect
07:04with that MQTT broker you can change the username okay you can change the
07:08password as per your requirement you can also create multiple user as per your
07:13requirement okay so I hope this thing is clear and if you still have any question
07:19or any confusion then you can always ping me on telegram Instagram whatsapp
07:22everywhere all the social media link is available here on our website okay so I
07:28hope everything is clear and now in the future videos we are going to cover this
07:33topic okay instead of Pico MQTT library we are going to use the embedded MQTT
07:37broker library to set up our ESP 32 MQTT broker and then after we will use
07:43SMQTT broker library to set up our ESP 32 as an MQTT broker okay so stay tuned
07:50for the future videos and if you have any question or any doubt then you know
07:53where to ask so we will meet you in the future videos till then take care goodbye
07:59and thank you

Recommended