ESP8266 connecting to internet
You should connect to the module as outlined in my first article about this module (which also shows use of some other commands).
To try out the commands in this post you should already have the module set up in STA or AP+STA mode and connected to router/internet.
If bray terminal works for you you can try using it for this example as it really has a neat function of being able to store multiple predefined send sentences (“Macros”) and access them at the click of a button. On my machine however for some reason the bray terminal doesn’t read the port correctly when there is a lot of data coming in (like receiving the content of a webpage) – I guess this has something to do with Windows 8. The display in bray terminal is also neater than the RealTerm used here.
AT+CWMODE=3 – set the module operating mode to STA+AP.
AT+RST – reset the module to finish changing the operating mode.
AT+CIPMUX=1 – enable multiple connections.
AT+CWLAP – check the available access points to connect to.
AT+CWJAP=”ssid”,”password” to connect to the access point.
AT+CIFSR – check the module ip and connection status.
AT+CIPSTART=4,”TCP”,”www.google.com”,80 – start the connection to google (you may occasionally get DNS fail, just retry the command)
AT+CIPSEND=4,42 -send 42 characters
When you receive > from the module send the following data (replacing \r\n with CR and LF characters):
GET / HTTP/1.1\r\n
You should get SEND OK and after that the content of the webpage requested in +IPD format. I get a 302 page moved result and a link to local google page google.si. If you malformed the GET request you will get a 400 error. The +IPD frames will be maximum of 1024 bytes long. If the webpage content is larger it will be split into several frames.
You should use AT+CIPCLOSE=4 to close the connection if the server doesn’t close it automatically. Otherwise you may get unexpected results.
By replacing the first / in the GET request with the url of your choice you can request any url on the www.google.com host. You can also send GET data to the server with it. When changing the request you also have to adjust the number of characters of request in CIPSEND command.
Obivously you can also get data from the server by looking at the content that is returned. Note that also HTTP header is output, not only the HTML code /content
Macros for bray terminal:
GET / HTTP/1.1#013#010Host: www.google.com#013#010#013#010#013#010