So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Borisw37
#66569 I'm using a HiLetgo ESP8266 with the native SDK (AT commands).
I would like to open a simple HTML page and display the HTML code in the terminal.
The ESP8266 connects to my wifi, I can ping an IP address, I can TCP connect to the page in question (AT+CIPSTART="TCP","64.78.59.92",80)

How do I receive the actual HTML text file?
User avatar
By QuickFix
#66613 Example using Google.com.

  1. First create a connection using AT+CIPSTART:
    Code: Select allAT+CIPSTART="TCP","google.com",80

    If successful. it will return:
    Code: Select allCONNECT

    OK
  2. After connecting, you'll have to tell the server what you want; in your case GET (retrieve) a page.
    Code: Select allGET / HTTP/1.0
    Host: google.com
    Connection: keep-alive
    Accept: */*

    First you need to know (by counting) the length of your request (in above example it's 68) and send it using the AT+CIPSEND=<length> command.
    Code: Select allAT+CIPSEND=68

    when succesful, it will return:
    Code: Select all
    OK
  3. Now you need to send your request and headers:
    Code: Select allGET / HTTP/1.0
    Host: google.com
    Connection: keep-alive
    Accept: */*

    When succesful, you'll get this as a result:
    Code: Select allbusy s...

    Recv 68 bytes

    SEND OK
  4. To get the actual data, use the command +IPD,<length>:
    Code: Select all+IPD,525:

    This *should* (see below for note) get you the actual HTTP-answer including payload (in our case an HTML page):
    Code: Select allHTTP/1.0 302 Found
    Cache-Control: private
    Content-Type: text/html; charset=UTF-8
    Referrer-Policy: no-referrer
    Location: http://www.google.nl/?gfe_rd=cr&ei=nzswWdXxMbOk8weHu5ioDw
    Content-Length: 258
    Date: Thu, 01 Jun 2017 16:06:55 GMT
    Connection: Keep-Alive

    <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
    <TITLE>302 Moved</TITLE></HEAD><BODY>
    <H1>302 Moved</H1>
    The document has moved
    <A HREF="http://www.google.nl/?gfe_rd=cr&amp;ei=nzswWdXxMbOk8weHu5ioDw">here</A>.
    </BODY></HTML>
  5. Lastly, close the connection with the server using the command:
    Code: Select allAT+CIPCLOSE

    Which wil return:
    Code: Select allCLOSED

    OK
Because I'm living in The Netherlands, Google will redirect me to the Dutch server (in the .nl TLD) of Google.

NOTE: To be honoust, I wasn't able to get the actual page, but ESPlorer does, so I must be doing something (minor?) wrong on a manual console. :oops:

Either way: I don't think using AT-command would be the way to go, but this is how it *should* be done. ;)