ESP8266: AT mode webserver tutorial


In today’s blog post I will show you how to implement a web server with ESP8266, using one WiFi3 Click and one USB-UART click from MikroElektronika. In this tutorial, I will use Tera Term to communicate with the WiFi3 click. Anyone can then adapt this tutorial to any microcontroller used to control the ESP8266.

This article is more than two years old and might contain obsolete information; it is still kept here for informational purposes.

The following connections were made for the WiFi3 click:

  • PWD (AN) pin is connected to Vcc via a 10k pull-up resistor. A reset button is connected between this pin and GND.
  • RST is connected to ground
  • EN pin is left floating
  • RX pin is connected to the TX pin of USB-UART click
  • TX pin is connected to the RX pin of USB-UART click

Please note that in the documentation on MikroElektronika website, the AN pin is marked as NC. This is wrong! On the click board, the marking is correct as being CH-PD.

When started, the board I have replied with:

Response to AT+GMR command is:

Note that some garbage can be received before the “[Vendor…”  text. This is normal, as ESP8266 starts first at 76923 bps, a baud rate that most terminal programs are not able to understand. So, just ignore this.

Connecting to WiFi and starting web server

The following procedure must be followed to connect to WiFi:

First, run AT+CWMODE=1 to configure the ESP8266 as a WiFi client.

Then run AT+CWJAP=”acess_point_name”,”wifi_password” to connect to an existing WiFi router. Note that it takes some time for ESP8266 to respond to this command, something over 5 seconds. Once connected you can get the IP allocated by the router with

One must configure the ESP8266 to accept multiple connections by running AT+CIPMUX=1. Then web server can be started on port 80, the standard http port, by running AT+CIPSERVER=1,80.

At this moment the web server is ready to receive connections. To further analyze the traffic, I used a TCP sniffer called SmartSniff. So, with SmartSniff active and listening, I typed in my browser.

A typical web request intercepted with SmartSniff should look like:

In Tera Term we will get:

The syntax of the +IPD response is +IPD,<ID>,<len>[,<remote IP>,<remote port>]:<data>. So, from the above-received Http request we extract the following useful information:

  • link_id is 0.
  • the length of the received message is 324

When parsing the message, we have to look at the GET command. The rest doesn’t matter much in my tutorial. However, one can use this information to deliver browser-specific pages.

So, we get the request, now we have to respond to it. The message we wish to send back is:

This message has 190 characters (including the <CR> and <LF> at the end of the message. So, we will run AT+CIPSEND=0,190.

Let’s take a look at the syntax AT+CIPSEND=[<link ID>,]<length>[,<remote IP>,<remote port>].

In Tera Term we will have an input prompt where we insert our message. When 190 characters are sent, the connection is closed and we get a SEND OK message. At the same time, the message content is sent to link_id = 0.

Finally, we have to run AT+CIPCLOSE to close the connection.

At this moment, in the web browser we should see the text “ESP8266 web server example by“.

Wait, there’s more…

The web browser issued another request, this time for favicon.ico. As we don’t have a favicon, we should return a 404 response, following the above procedure:

In Tera Term we will have:

Note that the request and the response use link_id=1, altough is the same browser

1 2

Comments are closed.