Excellent Arduino Ethernet Shield Web Server Tutorial

Hello all Arduino users.

I have found an excellent resource for making a web server using the Arduino Ethernet shield:

This is actually a set of tutorials and covers all the technologies necessary for making a web server.
It covers:

  • HTTP
  • HTML
  • JavaScript
  • Ajax
  • CSS
  • Web server hosted on SD card
  • Web server hosted without SD card

Someone commented on Twitter that this is possibly the best Arduino web server tutorial ever. After following it I can agree. 8)

So if you want to use the Arduino Ethernet shield as a web server, but are clueless where to start, then take a look at the tutorial - highly recommended.
Enjoy!

I only read the first few parts. So far so good. I wish I had see it before I started exploring. Thumbs up!

Thanks for sharing! You made my day!

Cheers!

L

Went through the Ethernet tutorial. Outstanding! Bookmarked the site.

Just wondered what hardware you guys are using? Which Arduino board / Ethernet shield (or the combo one called Arduino Ethernet) and has anyone used the WiFi shield with the tutorial?

I saw a post on this forum about all sorts of problems with the WiFi shield. Anyone have any luck with it?

Rog.

The tutorial is mostly independent from what hardware is used, ethernet or wifi. Yes, I am responsible for posting and replying a lot of these wifi shield problem threads :slight_smile:

The shield is not as stable as ethernet shield so if you want to try one, buy one that says R3 on it and never upgrade firmware. Then use arduino ide 1.0.2

liudr:
The tutorial is mostly independent from what hardware is used, ethernet or wifi. Yes, I am responsible for posting and replying a lot of these wifi shield problem threads :slight_smile:

The shield is not as stable as ethernet shield so if you want to try one, buy one that says R3 on it and never upgrade firmware. Then use arduino ide 1.0.2

Thanks for the info, liudr. I think I will wait a while before getting the WiFi shield.

I was asking about what hardware everyone was using out of curiosity, but good to know that the tutorial should work on most hardware. I am using a Arduino Uno before R2 revision and Ethernet shield v5. I think it is v5, the version number is not printed on the board and I am not sure how to find it. It looks like the one on shieldlist.org, so I think it must be version 5: Arduino Shield List: Arduino Ethernet Shield v5.0

The wifi client side is relatively robust enough on the other hand. I would wait a bit before spend the $100 USD for this shield. They just released a new IDE version and firmware for the wifi shield. If they have ears, I bet they are listening to the complaints and plan for future revisions right now.

How to access different network?

Web servers in this tutorial are used to serve web pages that can be accessed from a web browser running on any computer connected to the same network as the Arduino.

Thanks for sharing the tutorial, very good

Rog2323:
I was asking about what hardware everyone was using out of curiosity, but good to know that the tutorial should work on most hardware.

I'm using an nRF24L01+ module for Wifi hardware, LOL.

I've got an example AJAX webserver sketch that is directly derived from the one on the startingelectronics.com. It's actually a bit simpler than the original sketch. Here it is:

http://embeddedcoolness.com/faq/00500-ajax-web-server/

I developed the RFX system because I thought Wifi shields were way too expensive a solution for wireless Internet for Arduinos and related devices. So I looked at how to use inexpensive radio transceivers (nRF24L01+) in order to do the same things. (The low powered versions can be had for less than $5, and the high power versions for less than $20.)

It's now affordable to give all your Arduino/Arduino-like projects wireless Internet capability, if that's what you want. (I know it's what I want!)

I've got some code snippets in the docs on the site showing how to do some common things (like send emails, post updates to an Xively feed, etc.), but I'll progressively be putting up additional complete example sketches to show how to do these things.

Hopefully I'll find time to get some new examples up in the next few days.

Has anyone got this tutorial working ? I have problems with showing the webpage
I did this tutorial:

I've done other web server tutorial on that site and it work ( the none ajax).

I've also done another one from another site but both are based on David A. Mellis work.

and yes I've set the correct ip. I used the code as it was except for the IP and MAC

I use this code.
http://playground.arduino.cc/Code/WebServerST
It will keep port scanners and hackers like me from locking up your sketch. PuTTY is a wonderful tool. :slight_smile:

Thanks but that solutions will not have an interactive GUI and also it will produce addtional text in the url if you want to change a port value.

I require a ajax solution to meet my needs. so any other suggestions?

Search the forum for ajax with zoomkat as the author. He has some good ideas, even tho I can lock up most of his code in less than a minute.

My problem was that I removed the SD include and the SD code and added the html into the sketch ( because I couldnt find my memory card). So I just bought a new one and used the code as is( except the IP change) and it worked fine.

That server code is easy to lock up. I can do that in a few seconds with PuTTY. :slight_smile:

Most of zoomkat's code is more difficult than that. I need my Mega2560/ethernet shield to lock up some of his code examples. I'm not running down zoomkat here. He is a good guy and really smart, like I said in another post. His code has a few vulnerabilities if left exposed on the internet.

SurferTim:
I use this code.
http://playground.arduino.cc/Code/WebServerST
It will keep port scanners and hackers like me from locking up your sketch. PuTTY is a wonderful tool. :slight_smile:

Tim, can you explain what these vulnerabilities are, and how "locking up" the sketch is done, and also what it is about your sketch that avoids such problems?

Hackers are a bit hesitant to show vulnerabilities in code, but I am a good hacker, not a bad one. I try to prevent a hack. This code will lock up every server example I have seen, including zoomkat's. Follow the serial monitor prompts. Do not close anything until you remove the CAT5 from your Arduino. Change the network settings to suit your localnet.

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,2,2);
IPAddress gateway(192, 168, 2, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress server(192,168,1,254);
EthernetClient client;

void setup() {
  Serial.begin(9600);

  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  delay(2000);
  Serial.println("Ready. Enter l to lock");
}

void loop() {
  if(Serial.available()) {

    if(Serial.read() == 'l')      
    {
      if(!getPage(server)) Serial.print("Fail ");
      else Serial.print("Pass ");
    }
  }    
}

byte getPage(IPAddress ipBuf)
{
  Serial.print("connecting...");

  if(client.connect(ipBuf,80))
  {
    Serial.print("connected");

    // send request with no \r\n
    client.print("GET / HTTP/1.1");
  } 
  else
  {
    Serial.println("failed");
    return 0;
  }

  Serial.println(" & locked. Remove CAT5 from the shield.");
  
  return 1;
}

Rog2323:
Hello all Arduino users.

I have found an excellent resource for making a web server using the Arduino Ethernet shield:
Arduino Ethernet Shield Web Server Tutorial

When that tutorial gets to the point of doing something useful in part 5,

I believe the following lines have an error, he left out the self-closing tags, or else , on the elements.

    if (LED_status) {    // switch LED on
        digitalWrite(2, HIGH);
        // checkbox is checked
        cl.println("<input type=\"checkbox\" name=\"LED2\" value=\"2\" \
        onclick=\"submit();\" checked>LED2");
    }
    else {              // switch LED off
        digitalWrite(2, LOW);
        // checkbox is unchecked
        cl.println("<input type=\"checkbox\" name=\"LED2\" value=\"2\" \
        onclick=\"submit();\">LED2");
    }

The code will work ok for a single input-control, but hoses for multiple controls. This problem burned me for a couple of days, until I learned what the heck " />" was.

SurferTim:
Hackers are a bit hesitant to show vulnerabilities in code, but I am a good hacker, not a bad one. I try to prevent a hack. This code will lock up every server example I have seen, including zoomkat's. Follow the serial monitor prompts. Do not close anything until you remove the CAT5 from your Arduino. Change the network settings to suit your localnet.

#include <SPI.h>

#include <Ethernet.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,2,2);
IPAddress gateway(192, 168, 2, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress server(192,168,1,254);
EthernetClient client;

void setup() {
  Serial.begin(9600);

pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

Ethernet.begin(mac, ip, gateway, gateway, subnet);
  delay(2000);
  Serial.println("Ready. Enter l to lock");
}

void loop() {
  if(Serial.available()) {

if(Serial.read() == 'l')     
    {
      if(!getPage(server)) Serial.print("Fail ");
      else Serial.print("Pass ");
    }
  }   
}

byte getPage(IPAddress ipBuf)
{
  Serial.print("connecting...");

if(client.connect(ipBuf,80))
  {
    Serial.print("connected");

// send request with no \r\n
    client.print("GET / HTTP/1.1");
  }
  else
  {
    Serial.println("failed");
    return 0;
  }

Serial.println(" & locked. Remove CAT5 from the shield.");
 
  return 1;
}

Thanks. I got one serial monitor prompt and nothing at all after that. And nothing showed up at either URL on my PC [at 192.168.1.177 (my 'static ip') or 192.168.1.254].

I guess I'm too naive and confused to even understand what you're trying to do here. It seems to me you've established router connection at one IPaddress, but are trying to access the server on another,

IPAddress ip(192,168,2,2);

IPAddress server(192,168,1,254);

Hopelessly lost, so probably best to forget my question, :-(.