• 2 months ago
------------------------------------------------------------
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
00:02Welcome in this video. We will see ESP8266 as an MQTT broker
00:07So if you have a NodeMCU or also you can say ESP8266 and you want to use that board as MQTT broker
00:15Then how you can use it?
00:16So instead of using Mosquitto MQTT broker, Hive MQTT broker or EMQX broker or Nano MQTT broker
00:23You can use your NodeMCU board as an MQTT broker. So that thing we are going to cover in this video
00:29So we are going to use SMQTT broker library to create MQTT broker in the ESP8266 board
00:36I have ESP8266 board connected with my system and we will see how you can program your ESP8266
00:43To work as a MQTT broker. So let me show you the diagram
00:47So here we have our ESP8266 board in the center working as MQTT broker
00:53So any of your MQTT client can connect with that ESP8266 MQTT broker and they can exchange the data
01:00Now our ESP8266 board will connect with the Wi-Fi
01:03Okay
01:04And your Python MQTT client, NodeMQTT client connect with the same Wi-Fi and they can exchange data
01:10Using this ESP8266 MQTT broker. So I hope the diagram or the basic detail is clear
01:17Now let's move to the Arduino IDE and let's see SMQTT broker is installed in my system or not
01:23So here is the Arduino IDE and here I'm going to check that SMQTT broker is installed or not
01:29So yes, we have the SMQTT broker in my system. Okay, and
01:34NodeMCU is already connected with my system. So I am going to the example. Okay, and in the example
01:40We will search for SMQTT folder
01:43Okay here you can see SMQTT folder and I'm going to select the simple MQTT broker
01:49Example, so we will click here and we will open our simple MQTT broker example
01:54Okay, so here is our example now if you want to use this example
01:59Then you have to change two things first your Wi-Fi SSID and second your Wi-Fi password
02:04So if you want to use your NodeMCU board as MQTT broker
02:08Then first of all, we will connect our NodeMCU board with the Wi-Fi
02:12So other client can connect with the same Wi-Fi and they can use our ESP8266 as MQTT broker
02:19So first of all, we have to make connection with the Wi-Fi and then we can you know run the MQTT broker inside it
02:26So this is the entire code. Okay
02:28So in this code it will first connect with the Wi-Fi and then it will run the MQTT broker on the port number
02:351883 if you want to change the port then you can change the port number here and you can change your MQTT broker port
02:42From 1883 to any other TCP port number. Okay
02:47Now I'm going to provide my Wi-Fi SSID and the password and then we will upload this sketch into my NodeMCU board
02:54Okay, I have changed my Wi-Fi SSID and password and here is the MQTT broker port number
02:59So what I'm going to do is I am just going to upload this sketch into my NodeMCU board as you can see it is
03:05Already selected here
03:16Okay, so we have successfully uploaded our sketch into our ESP8266 board and here is the serial monitor
03:23I'm going to press the reset button on my NodeMCU
03:27And
03:29Here you can see the IP address. Okay, so this is the IP address of my NodeMCU board
03:33And we can use this IP address and 1883 port to connect with this NodeMCU MQTT broker
03:40So I can open my MQTT Explorer software. Okay, which is MQTT client software
03:47so I'm going to add new connection and it's my NodeMCU and
03:53The IP address of my NodeMCU is 192.168.1.9
03:58I am going to provide it here and here is the port number 1883, which is default in this example
04:04Okay, 1883. So I'm going to leave it as it is
04:07We will save it. Okay, and we will click on connect and here you can see we are connected
04:12Also, I'm going to again open the MQTT Explorer as my second MQTT client
04:17Okay, and here is our
04:21Connection. Okay. I'm going to change the client ID here. Okay, and then I'm going to connect
04:27So we are connected. Okay, our both the client is connected with our NodeMCU MQTT broker
04:34So basically we have uploaded the sketch into our NodeMCU board and then after it will
04:39Started acting as an MQTT broker. So I have this MQTT Explorer software in my system
04:45So I have opened two instance of this software and both instance are connected with ESP8266 board
04:52Okay, and now they are ready to exchange the data. So if I publish some data to any topic
04:59Okay, then on the second client we are able to receive that data
05:03So second second client is a subscriber. Now. The first client is the publisher now
05:08Now we can use our second client as a publisher
05:11so we are going to select the test topic and then we will publish some data from this second client and
05:16Our first client will receive that data. So our first client will act as a subscriber and our second client will act as a
05:23Publisher. Okay. So now you can use your
05:28NodeMCU board as an MQTT broker with n number of MQTT client and then you can exchange the data
05:34So if you are working in the home automation
05:36Or if you want to read any sensor data via Wi-Fi in your mobile phone in your tablet in your laptop or in your desktop
05:42Then you can use your ESP8266 board as an MQTT broker. Okay, it can be your central MQTT broker to
05:51Exchange the data. Okay. So this is how you can use your NodeMCU board as an MQTT broker
05:56So all you have to do is you just have to install this SMQTT broker library in your Arduino IDE
06:02then after you have to launch the
06:06Simple MQTT broker code from SMQTT broker folder in the examples
06:11okay, so simple MQTT broker code and then after you have to change few things and the few things is your Wi-Fi SSID and
06:18the Wi-Fi password to connect your
06:21ESP8266 board with the Wi-Fi and then after it will start acting as a
06:27MQTT broker and then after you can use it. Okay
06:30So, I hope this thing is clear and if you still have any questions or any doubt in this
06:35Okay, then you can always ping me on telegram Instagram. What's up anywhere? Also, you can comment on this video
06:40Also, you can send me a mail
06:42Now in the future videos, we are going to see how to set up secure MQTT broker in the NodeMCU
06:48Okay, so right now in this code, we don't have any username and password
06:53So when we try to connect with this broker, okay, we haven't specified any username and password
06:59Okay without specifying any username and password we are able to connect with that MQTT broker
07:04Which is running inside ESP8266, but we want to make a secure MQTT broker
07:09Then how we can do that? So that thing we are going to cover in the next video
07:13Okay, so stay tuned for the next video till then take care
07:18goodbye, and
07:20Thank you

Recommended