ESP8266 Send Data To a Website (ESP-01/ESP-12)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video I want to show you how to use your esp8266 module to send data to a website so what I have done is I have I bought a server with the URL esp8266 dot al-abadi e-comm and in the same server I created a text file called my file dot txt notice that the file is empty right now I have also created a script called receiver dot PHP and when I pass it the parameters apples 45 oranges equals 23 then these two values get rid into a text file so every time I visit this website and I change this number to anything I want then those values get rid into my file dot txt let me change the values one more time so these are the new values so this is what I'm gonna show you to do but instead of sending the data from my browser to the server we're going to use a pores the esp8266 module before I show you how to use the module let me go ahead and show you the receiver script that takes care of creating the file and writing the data so this is a receiver script is written in a language called PHP have a variable that I call var one that is in charge of getting the value from the apples parameter another variable called var two gets the value from the oranges parameter another variable that I made is called final content so this is what I want to put in the file the final status would be either true or false when this function gets executed this function creates a file puts the comp this content in this file and it appends the content if you don't want to append the content simply remove this parameter and the text file will get overridden every time with the new data I then check the status of the file if it's a success then I write success data written to file so this data that is this string that I have with the with an echo it's actually sent back to the browser in the case of the esp8266 this stream will be shown in the terminal the reason why so let me talk to you also about HTTP requests the reason why is this is get is because that is the type of request that I'm using I'm using get requests I will also show you how to use a post request in this same video but let's stick with the get request for now so what do we need to send data from the ESP module of course we first need to reset the module connect to a router connect to my server then specify the length of the get request this is going to be the length of my post request that I will show you later so to send a get request I have to send the string get space slash receiver that PHP a question mark followed by the parameters with the equal sign and the value for the parameters the parameters are separated with an ampersand symbol so my oranges will equal to 34 and let me change those numbers since I believe I've used those already will make the a post 56 the orange is 23 space HTTP / 1 / r / n to create a new line with a carriage return then I specify the host which is my server so this could be an IP address if you don't have a server like I do and then the end of command symbols so let me go ahead and open the terminal where I have connected my Wi-Fi module so let's go ahead and reset the module connect to the router connect to my server send the length of the get request string and then send the get request so I get the success message that I get in my browser which is what I had my script output whenever there was a success in the file getting reading so now if i refresh my file dot txt page then I get my 56 apples and 23 oranges sending a post request is also very similar in your receiver script you have to change get to post now your post request command is actually pretty different from your get request command this is the format of a post request so you put this line at the top this will be your script the content type the content length which is the length of the parameters and the values string so you can this carrot if you come the characters here there should be 25 then we put a blank line followed by the parameters and the values so or in our case this will be apples and oranges and actually they don't have to be in any specific order so they don't have to match the order of your receiver script they just have to be specified somewhere otherwise you will get an error if you don't specify either of the two parameters or you might get an error actually it depends on the version of PHP you're running in the server so the get request string has to be this information but all in one line and of course we have to include all the characters even the newline cat director which would be slash are slash end so we're going to send this line slash are slash end send this line slash are slash n this line slash are slash n and then to make another blank line once again slash are slash end followed by the parameter and the value so this is actually my post request string for my website and I will be sending the value of 12 for apples and 45 for oranges if you count the number of characters in this string then you will see that we have 154 so let's go ahead and give this a try so we connect to the website specify the length of the string request and send the string request we go and refresh the file and there you go that's it for this video thank you for watching don't forget to Like and subscribe oh yeah and I forgot one more thing you wanna there's actually some differences in in the cases for when you might want to use get and post I'll be posting a link to this website and there's actually a pretty good table that explains the differences so that way you can know when to use which one thing that's pretty important is that the pope request can actually send binary data the get request only allows for ascii characters when I say binary data I mean like you might probably want to send images or something like that which I might create tutorial for that later
Info
Channel: AllAboutEE
Views: 280,175
Rating: undefined out of 5
Keywords: esp8266, iot, interenet of things, wi-fi, esp-12, esp-01, arduino
Id: q02f4sPghSo
Channel Id: undefined
Length: 10min 23sec (623 seconds)
Published: Tue Dec 16 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.