Hello everyone, welcome to IoT Frontier. My name is Hariharna. In this video, we'll see how to simulate ESP32 integration with DHT22 with WalkPay, and send the temperature and humidity values to Node-RED dashboard using MQTT.
Stay tuned until the end of this video to get all the steps right. It takes time and effort to create content for you guys. So please share your support by liking this video, and hitting that subscribe button in my previous video i have explained you how to send temperature and humidity values using esp8266 that is node mcu with dht11 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 especially for you because we are going to use walkway so is a simulator tool that helps you to simulate any IoT project without a need of hardware. So let's first look into Wokwi.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 am selecting ESP32. So once you are selected you will be able to see the ESP32 and you will be having options to click here to add any new part.
So right now I need to add DHT22. So I'll add DHT22 and here we... be having VCC.
So VCC I will be connecting to 3V and HDA I will be connecting to B2. This is NC mains no connection, ground. Ground I can connect to here GND. 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 i've 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 i need to search for wi-fi and you will be getting a wi-fi here So once you have added it will be shown like this. Same way you need to add pub supply and DHT sensor library. So these are the libraries that will be helpful.
First one is to connect to Wi-Fi and second for MQTT pub sub. 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 libraries and given so based on ESP32 dev kit.
So this if you go to diagram.json you will be able to see what kind of board it is you can look into that it is a esp32 devkit cv4 so based on that i have searched in the internet and found out the gpio pinout so for d2 we can see gpio9 is the number so what i have done is i have given in the sketch you can see that dht pin is 9 dht sensor we are trying to initialize and if the walkway wi-fi you have to use their ssid that is what we guessed and password is is black and i'm trying to connect to the mqtt server that is 5mq so to connect to hive mq we have to use broker.hivemq.com so once you have done that you we are trying to initialize the wi-fi client as well as the pub sub client for using mqtt and these are some of the initializations that we have given for temperature humidity and different things so first we will try to set up the wi-fi so these are all the standard code for setting up the wi-fi to connect and these are the boilerplate 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 callback option whenever we are trying to receive any messages from MQTT then this callback function will be used but here 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 MQTT 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 a while loop.
The main code starts from set. So here you can see pin mode to initialize the built-in LED. So as we have written in the callback that whenever a message is coming, so we are blinking the LED. So that's why this is used. and this is the calling for the setup wi-fi that we have initialized there and setting the server of mqtt to 1883 and also initializing the callback 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 millis.
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 will be having data dot temperature. If you read data dot temperature. 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 slash temperature and here same way the humidity we are reading from data dot humidity and again publishing it to IOT frontier slash humidity so this is the topic that I have created so now you have seen the code this code even available in the GitHub.
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 ASP32 with DHT22 within WalkV. And also instead of using Arduino IDE, we are using WalkV itself to do all things.
And we have uploaded the code even if ready. And once that is done, we can just. Compile it by running the starting simulation. Before that, I will try to show you the next steps that we need to do. So next step that we need to do is, we have to set up the client that is receiver.
So for example, if you see the GitHub diagram, I am showing you is we have done the part of the first two setting up. So that is 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, 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 what I have to do is first I need to open PowerShell so in the PowerShell I will just type Node-RED so once that is typed 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 Node-RED is initialized, it will be giving you a server address.
So if you click on this, it will be opening to see the Node-RED homepage. The Node-RED homepage will be having a blank flow. But I have already created this.
That's why you are able to see these nodes 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 mqtt 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 5. 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 frontier slash humidity for which we are publishing. So that to subscribe here. So QoS I am 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 atomic so once the mqtt 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.payload so by this you can look into the you can also mention to check the debug window so 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 am also trying to send the humidity values and temperature values to the node-red dashboard so to install the node-red dashboard I have already mentioned in my previous video so you just can click on the top right corner to check how to install this dashboard so once you have installed the dashboard you will be able to see it notes so once 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 group so in the group I need to put the dashboard group name and also in which tab it has to look in the web page so I have created home and this is the name so once this is done you just need to 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 I chart. So once it's done, you have to click on deploy. This is also shown as connected. So next thing what we have to do is we have to check 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. 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 MQTT client as well as in the dashboard so go to the walk we click on this play button to start the simulation so it will first compile and then it will be trying to send the data so you can see it is trying to connect with mqtt once that is done you can see the initial values as humidity is 82 temperature is 44. you can just go to our node red we are able to see the live in the debug mode 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 this IP address copy this and use slash UI so once you do that you will be able to see these 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 walkv as esp32 simulator to integrate the dht22 and use mqtt broker such as hivemq to send it to the node-red which is subscribing to the topics of mqtt and also displaying on a dashboard 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 liked this video. Thank you for watching and I'll see you in the next video.