MQTT with ESP32 and DHT22 using Wokwi | Display on Node-Red Dashboard

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome to iot Frontier my name is Hara in this video we'll see how to simulate esp32 integration with dht22 with walk and send the temperature and humidity values to node red dashboard using mqt stay tuned until the end of this video to get all the steps back it takes time and effort to create content for you guys so please share your support by liking this video and hitting that subscri subcribe button in my previous video I have explained you how to send temperature and humidity values using ESP 826 that is node MCU with dhd1 sensor if you haven't watched it yet click on the top right corner to watch it now if you don't have any physical sensor or development board then this video is espcially for you because we are going to use walk V so walk V is a simulator tool that that helps you to simulate any iot Project without a need of Hardware so let's first look into walk.com you will first get to see that it will be having four boards that you can simulate so right now we are selecting esp32 so click on it and you have to go down and click on the starter template where I'm selecting esp3 so once you are selected you'll be able to see the esp32 and you'll be having options to uh click here to add any new part so right now I need to add DHT 22 so I'll add dht22 and here we be having VCC so VCC I'll be connecting to 3 volt and HDA I'll be connecting to B2 this is NC means no connection ground ground I can connect to here g& so I can adjust this wiring by dragging like this you can even change the color of it by clicking on this and the color will be changed to Green it's like that so once this is done I have already added the code so I'll just explain you here so here Ive made the connections as explained and here you can see the code has been written so before doing adding the code we have to First add the libraries so to add the libraries go to library manager and click on plus icon so here here I need to search for Wi-Fi and you'll be getting a Wi-Fi here so once you have added it will be shown like this same way you need to add pup sub client and DHD sensor Library so these are the libraries that will be helpful first one is to connect to Wi-Fi and second for mqt poab and here this is the DHT sensor library to read the temperature and humidity from dht22 so this is the sketch so here I have included the libr and given so based on uh esp32 dev kit so this if you go to diagram. Json you'll be able to see what kind of board it is you can look into that it is a esp32 devkit c V4 So based on that I have searched in the internet and found out the gpio pinout so for D2 We can see gpio 9 is the number so what I have done is I have given in the sketch you can see that DHT pin is n DHT uh sensor we are trying to initialize and use the walk V Wi-Fi they have to use their SS ID that is walk we guest and password is blank and I'm trying to connect to the mqt server that is hi mq so to connect to hi mq you have to use broker. hq.com so once you have done that you we are trying to initialize the Wi-Fi client as well as the pup sub client for using mqt and these are some of the initializations that we have given for temperature humidity and different things so first we'll try to set up the Wi-Fi so these are all the standard code for setting up the Wi-Fi to connect and this are the boiler plate code that you can get anywhere to connect so we are using SSID and password to connect and all these things will be done now we have even the call back option whenever we are trying to uh receive any messages from mqt then this call back function will be used but here uh in this code we might not be using it much so I'll skip this if you see reconnect here it is used for reconnecting uh mqd connection or the connecting it initially Whenever there is some issue so at that time it will try to reconnect automatically and that's why we have written in while loop the main code starts from set so here you can see uh pin mode to initialize the buil-in LED so as we have written in the call back that whenever a message is coming so we have we are blinking the LED so that's why this is used and this is the calling for the setup Wi-Fi that we we have initialized there and setting the server of mqt to 1883 and also initializing the call back that we have written previously and mentioning about the dht22 for setting up it next the loop code so here the important code where first whether the client is connected or reconnected so you can see the Wi-Fi connection being connected with the help of this code and this is non-blocking delay that we have given with MES uh so and later on you can see we are using the DHT sensor library to read the temperature and humidity that will be coming into Data so under the data we'll be having data. temperature if you read data. temperature uh so then you will be able to get the value of temperature same thing we are converting into string and printing here and once this is done so we are even publishing it to the topic called iot Frontier / temperature and here same way the humidity we are reading from data. humidity and again publishing it to iot froner /h humidity so this is the topic that I have created so now you have seen the code this code even available in the GitHub uh so here in the GitHub I'll be uploading the same code here so you will be able to get that based on the steps here we have initialized the libraries and even connected the esp32 with the hd22 with in walk and also instead of using ardino ID we are using walk itself to do the all things and we have uploaded the code even it is ready and once that is done we can just compile it by running the starting simulation before that I'll try to show you the next steps that we need to do so next step that we need to do is uh we have to set up the client that is receiver so for example examp if you see the uh GitHub diagram what I'm showing you is we have done the part of the first two setting up so that is uh the sensor connection with mqtt client and it is trying to publish to the mqtt broker so until this point we have done but if we want to subscribe and also show it in the graph right or any dashboard UI so for that we are going to use node red to use the node red uh what I have do do is for first I need to open Powershell so in the Powershell I'll just type node red so once that is tyed if it is not installed you have to install it so I have mentioned in my previous video how to install node red you can find the link in the top right corner and so once the no R is initialized it will be giving you a server address so if you click on this it will be opening to see the no R homepage the no homepage will be having blank flow but I I have already created this that's why you able to see these notes added so for example if you take a blank flow it will be like this you just need to add nodes so first you need to add mqtt in so you need to drag mqtt in and you need to configure multiple things in it so what I've done is I've already done so you can just look into it so I have done I have Dragged mqt In and inside that you can see the server names the broker that we are using right those things are mentioned here so you can click on edit and add the server Port connected automatically has to be checked and the protocol so you can use 3.1.1 or five also keep alive all these are default so once this is done you need to click on action and select the subscribe to single top and also you need to use the topic as iot froner / humidity for which we are publishing so that to subscribe here sec viers I'm using it to here the same way you need to do for temperature so temperature again you need to set up the server and the only thing will change is the to so once the mqt in has been set up you can click on debug node you can drag and drop debug node and here you can just set up the output as MSG do payload so by this you can look into the uh you can also mention to check the debug window so that that whenever the message is subscribed you can see those messages in our debug window here so along with printing it here in the debug window I'm also trying to uh send the humidity values and temperature values to the uh node red dashboard so to install the node red dashboard I've already mentioned in my previous video so you just uh can click on the top right corner to check how to install the dashboard so once you have installed the dashboard you'll be able to see its notes so once uh you have seen this you can click on gauge and also you can drag and drop the chart so those things I have already set up you can just look into here so in the humidity I need to set up the group so in the group I need to uh put the uh dashboard group name and also in which tab it has to look in the web page so I created home and this is the name so once this is done you just need to uh provide the type and label of which you have to show there and a value will be in this format same way for the temperature the chart I'm using the label here and type is time chart so once it's done you have to click on De deploy this is also shown as connected so next thing what we have to do is we have to check the our diagram so we have done the fourth step also where the mqtt client setup is to be done so all the steps is done what we have to do is now go to walk we and click on start simulation so that we can publish the data and we can see them in the mqd client as well as in the dashboard so go to the walkway click on this play button to start the simulation so it will first uh compile and then then it will be trying to send the data so you can see it is trying to connect with mqt once that is done you can see the initial values humidity is 82 temperature is 44 we can just go to our node red and we are able to see the live in the debug node so you have to click on this so that you can see the debug values now this is done this flow and we want to go to dashboard view as well right so for that we have to just click on this uh IP address copy this and use slash UI so once you you do that you will be able to uh see these uh tabs that we have previously mentioned in the Home tab I have this temperature humidity and here you can see the value of 82 and the value of 44 now let's try to change those values so what we provides us to even change the values so if you click on dht22 you can just drag and drop the values so now I have taken 2.5 centigrade and humidity is 44.5 same thing we can look here 44.5 and even this has gone to 2.5 again if I try to increase it 74 and 90 immediately you will be able to see the spike here so that is how we are able to use walk v as esp32 simulator to integrate the dht22 and use mqtt broker such as hmq to send it to the node red which is subscribing to the topics of mqtt and also displaying on a dashboard Bo I hope this video was helpful for you please comment below what tutorials you would like me to make Next One Last Thing Before You Go please hit the Subscribe and like button if you like this video thank you for watching and I'll see you in the next video
Info
Channel: IoT Frontier
Views: 2,794
Rating: undefined out of 5
Keywords: wokwi, mqtt wokwi, esp32 simulation, mqtt in esp32, simulating iot projects, ESP32 pubsub, ESP32 mqtt subscribe, mqtt publish, wokwi esp32 simulator, wokwi simulator, wokwi arduino simulator, wokwi esp32, wokwi projects, mqtt protocol in iot, mqtt tutorial, mqtt esp32 tutorial, mqtt esp32 arduino ide, mqtt with esp32, how to simulate esp32, integrate mqtt with esp32 and dht22, integrate esp32 with dht22, node red dashboard, esp32
Id: fbQRF_IKuo4
Channel Id: undefined
Length: 13min 21sec (801 seconds)
Published: Mon Jan 15 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.