ESP8266 Tutorial AT Commands

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video I'm going to show you how to use your esp8266 Wi-Fi module this is a microcontroller independent tutorial meaning that the stuff you learn in this video will apply to any microcontroller that you use so let's go ahead and get started first thing I want to show you is the command syntax for your module so every command is preceded by a t plus then you type the name of the command so you will replace the brackets in the X's with the command name in this case so I have an example here that it's called the command is called CW mode and if you put an equal sign and then a question mark after the command name then you get a list of the valid parameters so let me go ahead go ahead and show you the output of that command and I will show you how I'm interfacing with the module in a moment so if I send 80 plus CW mode equals question mark also at the end of every command you have to type / r / end which stands for carriage returned and then new line feed so I'm going to go ahead and click send so the equal sign and the question mark after the command tells you the possible values for that option in this case the possible values for CW mode are 1 2 3 I will explain the commands in a moment right now I'm just showing you the syntax so like I said this tells me that I can give the values 1 2 3 to the command if I want to display the current value of a particular command I just have to type the question mark after it so for the same command I'm going to type 80 + CW mode question mark so that tells me that the current value that CW mode has is 1 if I want to give a value or assigning or assigning value to a command I have to simply put equals in the value that I want to assign so in this case I'm setting CW mode 2 to remember that the possible values are 1 2 3 so now that I said it to 2 let me use the display value command to show you that it worked so now notice that previously the CW more value was 1 now the value is 2 let me go ahead and change it back to 1 so that is the syntax for looking at the possible values the current value and setting a value now what if there are actually some commands that have multiple parameters so you have to assign multiple values one of the commands is the join access point command which is a t + CW j AP so j AP stands for join access point and that command is used to join a Wi-Fi network or in other words how to connect to your internet router so if a command has multiple values then you have to separate each of the values with a comma and if the value can be either a number or a letter or if we can include letters and numbers then you have to put it in quotes if it can only be a number then you don't have to use quotes so in the case of a username or a access point name which is SSID and the password for the SSID both of those can either have can have numbers and/or letters so they have to be put in quotes so let me go ahead and show you how you connect to a router so I'm going to connect to this router actually have two routers so this is a router that I'm going to connect to so my SSID is ATT 4:09 so I'm going to type cwj AP ATT 4:09 comma and now i'm going to type my password so the password for this network so this is a password actually uh that number is something that I put at the end so I don't connect to this router since this is my low speed router so the password for this router is actually this one so I'm going to go ahead and type it and then send the command and it's gonna take just a couple of seconds to join the network so as you can see here it has joined the network I have received the value of okay let's see what happens if I type by an incorrect password so this can this will probably take a while to verify it so notice that it says fail then go ahead and connect to it again so the okay and the fail are responses that I'm getting from the module I'll show you the circuit that I'm using in a moment so that is how you can use a command that has multiple values there are some commands that they just display information or do something in particular for example this is the there's the reset command that resets the module this one I believe gives you the firmware firmware version of the module so let's go ahead and use that one 8080 plus GM R so that is my firmware version CI FS are gives you the IP address of the module so that is the syntax for the commands you can find the commands online in many websites I'm going to be posting the links to the websites where I found the commands that I'm using so this is one of the websites this is the Chinese datasheet for the module so this one has all the commands in in case some of the websites are missing them you will be able to find them in this datasheet and I will post the links to everything that I'm showing you here in the description of this video so now that you know the command syntax let me go ahead and show you the connection the circuit that I'm using and all the equipment so this program that I'm using is called real term it's a program that can read serial ports so my settings for this program are my bat already set at 9600 and my port is 22 so this is a port where my module is connected to so I go to computer management you're going to see that I have one USB serial port and that is comm 22 so that is the port number that I have here you can find the bar trade in the in the if you body form if you've got your module for movie you can scroll down in in the case of the seller that I got it from it tells me the the speed that I need to use so so this is the speed that I need to use and this is the data bits the parity in the stop bits so that is my configuration here the priority is none that's what the end is stands for data bits eight dot 9600 stop bits one so you can download this program from this website I'm also using a 5 and 3.3 volts power supply that I got from Sparkfun so this is what I'm using for powering up my circuit the adapter that I'm using for this power supply is this one so the way I'm connecting this module directly to my computer is through an FTDI to USB cable so this is a pretty neat cable it lets me connect any any device that has an Rx and TX pin directly to my computer so this is a cable that was meant to be used for the Raspberry Pi but I'm using it for this since it has the same the same interface so the cable has three three connections a black cable that's foreground the orange cable is the TX pin and the yellow cable is the RX pin and then of course the Wi-Fi module so this is my circuit schematic this is my FTDI cable FTDI to USB cable so the RX pin from the module goes to the TX pin of the FTDI cable the TX pin from the module goes to the rx pin of the FTDI cable and then the grounds are tied together so you can replace this FTDI cable with a microcontroller the microcontroller so you would also have a TX Rx and ground pin and in a pairing up the circuit from 3.3 volts so the power supply that I bought gives me the option of using 3.3 volts which is what the module needs and then of orser's se then from my cable that goes to my computer and that's how I'm sending and receiving the commands but you can do that for my microcontroller but this I'm trying to keep it as microcontroller independent as I can and then in other videos I'll show you how to use the Arduino and the microbes that I use so let's go ahead and do a real application let's go ahead and get the weather from the Internet so the first step of course is to power up your circuit let's go ahead and reset the module so let me go ahead and open the terminal so I'm going to type a t + RS t / r / n and let me go ahead and clear the screen so you can see the output of the module so let me go ahead and send that command again so I was even okay and then I receive some other information after the reset now let's go ahead and join the access point so once again I'm using the CW join access point command in my routers name and password so I don't Lee I've joined the access point so now we are connected to the router now before I show you how to get the information from the internet I need to show you the website where I'm getting it from so there's a website called open weather map that org so if you go to this link and they have several information they can provide you with we're going to get the current weather data so that is what is happening right now in a particular city they give you the formats that you can use so the one that we're using is we are searching by city name and they give you an example so you wanted to look at the weather in London which is in the UK you would put this in your in your browser so I click on it it takes me to this website and then it gives me a bunch of information not just the weather but my weather information is actually located here this is the temperature that's in Kelvin degrees pressure humidity which I assume it's percent RH or relative humidity you want it to get late for example San Francisco and that's in the u.s. press Enter so that gives me the information for San Francisco so what we need to do from the module is we need to go to this website and the way we do that is we start first we we connect to the website so this is how we connect to the website so notice that I got this I got this website name from my from here so that's what I put there so we always put CP name of the website the port that you're using is normal it's 80 so just go with 80 so I'm using the command CIT start and I have to do now the problem with this is that if I I have to do the following three commands fast otherwise I'm going to lose connection to my network so this connects to the website if I don't send the other ones fast enough then I will lose connection to it so let me go ahead and explain to you the other two commands that we need to send after this one and then obvious send them fast when I'm using the real term so now that you know the syntax for this command that connects you to the API after you are connected you have to send the data bytes the number of databases you're sending so you need to tell the module how many data base you're sending so how do you know how many data bytes you're sending well we have to know a little bit about HTTP requests in the case of this API this uses an HTTP GET request the reason I know it's a get request is because at the end of the URL in a get request you always see the the question mark then you see a parameter name the equal sign and then the value of that parameter so that's how I know that this is a get request so then I type get this is the path for the API so that would be whatever is after the URL or after the main website name or the main API name so you send the type of request the path there's actually space between us and HTTP so in case you you can barely see that but there's actually space there after that you send the HTTP version then you want to send the slash are slash end which signals the module that you're about to send another command then you give it the name of the host API so once again that's the name of the website so in this case this would be the IP address but we can also use the website name but in here you have to actually use the the website name or you cannot you might be able to actually also use the IP address in this example so that would be your host and then we have to set this number of characters so slash are slash in three times so let's go ahead and get the data so I'm going to copy this line paste it send it notice that my module says that it's linked now I'm going to tell it the number of data bytes that I'm sending so I'm sending 85 and then the module replies with this greater than character and then I send my HTTP GET request and I get the response that I was expecting so for San Francisco until it tells me like I said more information longitude/latitude let me go ahead and find the temperature so that is the humidity 93% that's the temperature 284 0.42 degrees Kelvin now one thing I forgot to show you is how do you know how many data bytes you're sending so the number of data bytes is the number of characters in this stream so if you count the number of characters that you're sending between from when you start right before get so it's one two three four all the way to here so the last two characters don't count since they are the ones that the module uses to know when you have terminated a command so only count these characters and of course /r is one character so those are not two characters that just want slash end is another character that's the newline character and also make sure that this you come this one is only one and this one is just one also so if you can the number of characters from here all the way to here you will see that there are 85 and so that's why I get my data lengths that I use in the CIP send command now of course this isn't a very good API response that we can work with but on your microcontroller probably has a library that can parse this type of response this type of response is known as a JSON response so we go back to the API is website you will see that it says that it can provide you with a JSON XML or HTML format these are the ones that are most commonly used for communicating or sending data through the web so look for a library or your microcontroller that came parse JSON and/or XML data and that is how you use the esp8266 Wi-Fi module thank you for watching
Info
Channel: AllAboutEE
Views: 146,028
Rating: undefined out of 5
Keywords: esp8266, Wi-Fi (Invention), esp8266 tutorial, esp8266 datasheet, wifi tutorial, tcp, http, openweathermap api, esp01, esp12, Server
Id: uznq8W9sOKQ
Channel Id: undefined
Length: 23min 19sec (1399 seconds)
Published: Fri Dec 12 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.