Simulating IoT projects in Wokwi | MQTT in ESP32

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to high voltages in this video we will learn how we can simulate our iot projects using work V what is work V we will discuss this in the next slide in this video we will use amgridity protocol in esp32 to send temperature and humidity values and control the LED Servo motor and neopixel RGB strips using mqtt let's discuss what is work V we will explore this Innovative iot development and simulation platform that has revolutionized the way we create and test iot projects let's dive into the key points on this slide walkway is a platform specifically designed for iot developers it provides a virtual environment for creating and simulating iot projects with walkway the process of building iot projects is simplified through its user-friendly interface it eliminates the need for complex physical setups reducing development time one of the unique aspects of workfree is its ability to bridge the cab between in hardware and software it allows developers to design and test both aspects in a cohesive manner walkway enables real-time testing offering immediate feedback on Project performance this feature AIDS in detecting bugs and errors early in the development process whether you are working with an Arduino esp32 or other iot platform walkway has you covered it supports popular programming languages like Arduino micro Python and circuit python now let's see which ports and programming options are available in workfree walkway has support for Arduino Uno Arduino Mega esp32 Arduino Nano Raspberry Pi Pico micro python on esp32 micro python on Pi Pico and the list goes on most of the features in walkway is free but some premium feature requires you to buy membership which at the time of recording is seven dollar per month before starting make sure to subscribe and if you find some values in my videos make sure to like and share so let's start simulating our iot projects in work V so we will first go to walkway.com and we will sign up for an account if you don't have any account we could sign up using Google and once you have signed in you could go to my projects and click on new project and we will select esp32 here okay so this is this is where we will make our circuit and this is where we will write a code and here we could add libraries as well from here you could search for any Library so let's run this code so you could see Hello esp32 is printed since this code was supposed to do this okay so let's stop this and let's make the connections so I will remove this code and first I will add an LED and a register you can rotate it by using the r key now I will import the dst22 so this is the dht22 sensor and we have VCC STA and this is ground this signal pin we will connect this to D12 okay now I will add a Servo motor so we will first connect the VCC and then we have this crown and we will connect this pwm to pin number D2 I will change the color of this pen and now I will add Neo pixel and for that we have ground VCC D input so first let's connect the ground and then we have this VCC then we have this T input pin which we will connect to pin number D4 so our circuit is ready now let's write code so first we will include the libraries we have some libraries here add a fruit sensor and DST us for dht22 sensor Wi-Fi library is to access the Wi-Fi Pub sub client is for mqtt Servo libraries for using the servo motor and fast LED is for neopixer now we have to add these libraries from the library manager as well so I will import DST ensor Library okay it has imported all the libraries by itself then I will Define the pins and then we will Define the parameters of DST and then we will make an object of Servo motor and now we will Define the object for neopixel here we have defined the number of LEDs which we have already defined here 16 and then we will Define the parameters of Wi-Fi so if you are using Wi-Fi in the walkway simulator you could use this SSID and password you have to keep it empty and then we will Define the mqtt parameters so this is our broker that we are going to use and this is our topic on which we are going to publish data and this is our client ID and then we will Define some parameters for using non-blocking delay and then we will create some variables to store temperature and humidity data and then we will set up Wi-Fi and mqtt client I have explained all this code in my previous video in which we used esp32 and mqtt protocol and then we will create a function to set up the Wi-Fi and then we will write some functions for mqtt so this first function is the reconnect function it will check if we are already connected to mqtt broker then it will subscribe to some topics on the lights topic we will receive the LED data and on the server we will receive the servo data and on the neopixel topic we will receive the colors RGB values for this neopixel LED and if it fails to connect to the mqtt broker we will see an error here then we will create a callback function so the Callback function will be called when any message arrives on any subscribe topic so first it will print the message and then it will check if the topic is lights then it will check what is the message if it is on it will turn on the LED it will write digital right High and otherwise it will set led to low and if topic is Servo it will convert the data to integer and write that value to the servo motor so Servo motor will move to that specified degree and if the topic is neopixel it will extract red green blue value from the message it will print all those values and then it will write those values on the LED using the fast LED library now we will write our setup function in the setup function we have defined the serial begin to initialize the serial communication and DHT begin to initialize the DHT sensor we set the initial Servo angle to 0 and we initialize the neopixel LED and then we call the setup Wi-Fi function to connect to the Wi-Fi and then we set server for mqtt by giving the mqtt server broker address and the port number and then we Define the Callback function which we have already initialized then we will Define the loop function so in the loop function it will check if we are connected to mqdt broker if not it will call the reconnect function which will try to reconnect to the mqtt broker and then we have defined a non-blocking delay after every one second the value of interval is 1000 that means one second we will read the temperature values and humidity values from the dst22 sensor and then and then we publish that data to the topic the topic we have defined here temp data so that's it let's run this program the pub sub client library is not imported so I will import it here and we need the esp32 server so now you see we are connected to mqtt and it has started to publish data we can change the temperature value by clicking here and you will see the temperature and humidity values are increasing now let's test this this is a graphical user interface which I have created on node red node red is subscribed to the same topics and is using the same broker so any change that we make here will appear on the Node red as well for example let's change the temperature and you will see the temperature where data has been sent to the node red using mqtt and similarly we can change the humidity values and these are the charts for humidity and temperature similarly we can turn on or off the LED you could see the LED is turning on and off and similarly we could move the servo motor you could see the servo motor is moving this is 180 degree and if I move it back it is 0 degree now and I could change the colors of neopixel her screen let's change it to Red so that's it for amqtt in node red and how to create this dashboard in node red I will create another video for now thank you for watching please like share and subscribe for more such videos
Info
Channel: High Voltages
Views: 13,610
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 raspberry pi simulator, wokwi projects, mqtt protocol in iot, mqtt tutorial, mqtt home assistant, mqtt esp32 tutorial, mqtt esp32 arduino ide
Id: lEXQ9w1z7Aw
Channel Id: undefined
Length: 11min 16sec (676 seconds)
Published: Fri Jul 21 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.