ESP8266 To ESP8266 Data Transfer Using Web ClientServer Arduino IDE Mac OSX and Windows




ESP32,ESP8266,Arduino,IDE,NodeMcu,Tutorials,Makers,Learn,Guide,IoT,Internet Of Things,Raspberry Pi,Wireless,Communication,Weather,Creative,Sensor,Python,Programming,C++,Beginner,Electronics,DIY,MicroPython,3d Printing,CAD,Fusion 360,Education,Tutorial,Intro,Introduction,Web,Developer,HTML,Datalogger,Project,Sensors,Data,Visualization,Webserver,Server,Client,App,WebApp,Wemos,Robot,Robotics,Robots,Easy,Adafruit,Sparkfun,OS X,Windows,Linux,Embedded,Kickstarter,RC,Fun,Build,Engineering

in this video we're going to use two esp8266 to send data from one to another we're going to configure one as an access point to run a web server and another as a client to collect temperature data and send it to the server alright let's do this [Music] this video is sponsored by skill sure skill sure is an online learning community for creators with more than 27,000 classes in design business web programming and other categories in a few of my videos you've seen me use javascript HTML CSS and other web design technologies that you can easily learn using Skillshare the first 500 of my subscribers can use the link in the description and get a 2 month free subscription to try things out we're going to start by creating a new file it will contain the code for the server and access point part of the project the first thing we'll do is include both the Wi-Fi and the web server libraries for the esp8266 next we'll define the variables that we're going to need for configuring the access point namely the SSID the password the IP address the Gateway and the subnet that the access point is going to have all these parameters are arbitrary and you can set them up however you want we'll create an instance of the esp8266 web server class so that we can set up the web server and for the temperature data that we're going to be collecting with a client on the server side we'll need a global variable that I'll name sensor value in the setup function the first thing we'll do is create the access point we'll switch the mode to Wi-Fi ap we'll use the soft IP config method of the Wi-Fi object with the variables we defined earlier to configure it and we'll use the soft AP method to actually start the access point the IP address of the access point will be the one we defined however as a sanity check I'll just print it out on the serial monitor so that we can see that things are actually working after the access point is running we'll use a couple of routes to handle the traffic from clients on to the web server the first one is just the top root path and will serve a very simple index page I'll use a function that I'll name handle index when the table path is accessed will simply send back the latest measurement that's been reported that means that we need to make a request each time we want to see the latest measurement the other route I'll use alcohol update when that route is access it'll call a function that'll name handle update in that function I'll simply update the sensor value as reported by the client we can do this in different ways I'll choose what I think is the simplest one which is getting the value from a URL parameter we'll use the arc method of the server object and look for a parameter name value that will convert to a float from a string I'll print it out on the serum monitor and I'll send a message back to the client to say that the value has been updated we'll finish up by calling the handle client method inside the loop function and the begin method inside the setup function I'll save the file onto my desktop and I'll simply create a new folder called esp8266 server client and this is the server side of the project so I'll simply call the file server we can go ahead and test things out I'll go ahead and connect the note MCU board which I'll use as the server to USB make sure that the USB drivers are installed as we've done in other videos I'll select the board and the port from the Tools menu and upload the code I'll then go on to my Wi-Fi connections and see that the access point is available I'll connect to it and once the connection is established I'll go to the IP address that I define for the access point as we haven't updated it we get the initial value displayed on the page I'll open a new tab and use the route update with a URL argument named value with an actual value of 28 point 3 and see that if i refresh the top loop path I'll get that new value with the server side done I can go ahead and open a new file for the client I'll save it inside the same directory and pull it client on the client side we'll only need the esp8266 Wi-Fi library we'll use a couple of variables for holding the values that we're going to read from the TMP 36 sensor and of course we'll need the variables to hold the SSID password and IP address of the access point we just created we'll also need an instance of the Wi-Fi client class in order to send the data to the server I'll configure the sensor pin as an infant but this is the default mode so it's an optional step it makes the code a little bit easier to understand I can then connect to the access point as we've done in other videos in this case we'll use the SSID and password of the one we just created I'll print out the IP address which will be assigned by the access point next we'll get a measurement from the TMP 36 sensor will use the analog read function to get a digital value from 0 to 1023 we'll multiply it to convert it to volts by 3.3 and divide by 1024 and then we'll use the datasheet of the sensor to convert that volt value onto an actual measurement of temperature in degrees centigrade I'll print it out to the 0 monitor to ensure that things are working properly now to send the value to the server we'll use the client object first with the connect method of the class we'll connect to the IP address of the access point will then create a request to the update route with the URL parameter value and the value we just got from the sensor we'll use the print method of the Wi-Fi client class to send a get request to that route with the URL parameter we'll configure a couple of other parameters of the header of that HTTP request will delay for a sure amount of time and then we'll print out the response from the server we're ready to test things out for the client I'll be using the windows d1 mini development board for the esp8266 the connections of the TMP 36 sensor are pretty straightforward the data pin I'll connect to pin a0 which is the only analog input pin on the esp8266 the power pin I'll connect to 3.3 volts and the ground pin to ground with this connections made I'll go ahead and connect it to USB and once again remembering to install the USB drivers as we've done in order I'll select the corresponding board and the corresponding port for this specific port I can tell which board is which because they use different USB to serial chips which are named differently in the arduino ide i'll upload the code i'll open up the serial monitor see what value is being measured and refresh the page to create a new request to the server indeed i see that the value that was reported is displayed on the page because we're performing the measurement inside the set of function it only runs once and the reason for that is because i wanted to show you how to use the deep slit method in order to have the port go to a low-power mode in between measurements so if we go back to the IDE we can define a variable that'll hold the value in seconds of how long we're going to sleep for in between measurements for now I'll simply use two seconds but this can be the time that you actually need in order to save battery in case the board is running on battery power the only thing I'll need is to call the deep sleep method of the ESP building object with the time for which I want the board to go to sleep I'll then connect a wire from the pin d0 to reset so that the board can reset itself once it comes out of the deep sleep mode we'll let it run a few times and if I go back to the website I can refresh and see the new value being updated and if I mess around with the sensor put my finger on it I can increase the values and refresh the page to see this new values being reported and that's it we've learned how to use the Wi-Fi client and the Wi-Fi server classes in order to send data from one esp8266 to another if you like my videos I invite to my patreon page where you can chip in a buck or two that really helps me put in more time into the videos and release them quicker but whatever you do don't forget to like subscribe or leave me a comment you can also interact with me on social media I'm on Instagram Twitter and Facebook and you can even use the community tab of the channel thank you for watching my videos and I will see you next time [Music] you