ESP8266 Arduino Webserver

Merry christmas everyone. I have a present for you.


A sketch with a simple modified webserver for the ESP8266 AT firmware using an arduino. Most credits go to this guy, where i got the basics : .

What my sketch basically does you might ask?

Well, it first boots up as an AP (access point), you connect to it (just like you connect to your wifi, it should be named something like ESP-???) and access in your browser Here you will see a very simple webpage where you enter the SSID and password of your wifi network, and then it connects to it. After this you can do all sort of things. In this sketch it just shows the same webpage again.

I did this to learn how to use forms with GET method to send and receive data (to fiddle with sensors, use it to turn LEDs on and off, etc).

I won’t post here the full code because i will upload the file and you can also find the simple webserv on rayshobby.

The function “get_data” is very simple and reads what comes out after the /get request. Ignore if it request the favicon.ico (very annoying, chrome sends a request for every refresh of the page – arrrhh), simple display the website if it’s a simple “/get” as if you are accessing the webserver, and if there is a question mark character store the data using the sort_data function. (if you input data and press connect, i will have to add to check if the strings are empty, or if it connects successfuly, this is just a basic sketch)

Please modify the port if u want (but you will have to access the ESP like and the baud rate. You need to update firmware to be able to change baud rate. I use this one.

I will post a simple tutorial about how to simply turn a led ON or OFF soon but if you understand the code, it should be simple enough. Enjoy!

Download the arduino sketch.


9 thoughts on “ESP8266 Arduino Webserver

  1. Hello i wonder if it is possible to put a password on the page before entering it that way no one can change the ssid or password?

  2. Hello i was wondering if there was a way to put a password on the page so that no one can change the ssid or password?

    • Cezar Chirila says:

      Yes. You can definitly do this. Just insert this javascript
      Also check out .
      My code is a bit oudated there are better that don t use at+ commands.

  3. zee says:

    This code is showing this error
    “exit status 1
    ‘setupWiFi’ was not declared in this scope”

    Please upload a esp8266 username and password code

    • Cezar Chirila says:

      Are you using my code from google drive? I just checked and I can compile it :
      “Done compiling. Global variables use 1,411 bytes of dynamic memory.”
      What version of Arduino are you using? I use 1.6.5.

  4. zee says:


    const char* ssid = “Bin Nadeem Associates”;
    const char* password = “35577F48”;

    int ledPin4 = 4; // GPIO4
    int ledPin5 = 5;
    WiFiServer server(80);
    WiFiClient client = server.available();

    void setup() {

    pinMode(ledPin4, OUTPUT);
    digitalWrite(ledPin4, LOW);
    pinMode(ledPin5, OUTPUT);
    digitalWrite(ledPin5, LOW);

    // Connect to WiFi network
    Serial.print(“Connecting to “);

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
    Serial.println(“WiFi connected”);

    // Start the server
    Serial.println(“Server started”);

    // Print the IP address
    Serial.print(“Use this URL to connect: “);


    void loop() {
    // Check if a client has connected
    WiFiClient client = server.available();
    if (!client) {

    // Wait until the client sends some data
    Serial.println(“new client”);

    // Read the first line of the request
    String request = client.readStringUntil(‘\r’);

    // Match the request
    int value4 = LOW;
    if (request.indexOf(“/LED4=ON”) != -1) {
    digitalWrite(ledPin4, HIGH);
    value4 = HIGH;
    if (request.indexOf(“/LED4=OFF”) != -1) {
    digitalWrite(ledPin4, LOW);
    value4 = LOW;

    // Set ledPin according to the request
    //digitalWrite(ledPin, value);

    // Return the response

    client.println(“HTTP/1.1 200 OK”);
    client.println(“Content-Type: text/html”);
    client.println(“”); // do not forget this one

    client.print(“Led4 pin is now: “);

    if(value4 == HIGH) {
    } else {
    client.print(“Led5 pin is now: “);

    if(value5 == HIGH) {
    } else {


    Serial.println(“Client disonnected”);


    I’m using the following code. But I dont know how to store the password and username in a variable that will come from the web page. Plz help.

  5. Hello, I am using arduino nano with esp8266-01.
    The compiling and uploading goes well but in the serial monitor I get this after entering ssid and password in the browser –

    link is not
    link is not

    complete log :

    please help me out.

    • Cezar Chirila says:

      Sorry for the slow response.
      Here is the problem :
      “if(wait_for_esp_response(2000, “> “))
      else {

      So you aren’t getting a response from the ESP. First of all, is the firmware the one posted on the page?
      I have to admit that my code is old and the ESP8266 evolved greatly, you should try the newest AT firmware, but you will have to change some code because the commands are different. But if you want to use my code, first please check that the firmware is the one above. Second, you can connect to the ESP8266 via browser and the page appears?

      PS. The link isn t valid anymore.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: