Arduino Webserver

I am attempting to build an Arduino based webserver. I am using an Arduino Uno with Ethernet Shield and version 0023 of the IDE. The basic gist of the application is this. Pass a pin value to the Arduino using the address ie: http://10.1.1.8/?pinD2=1 to set digital pin 2 high. The Arduino sees this incoming request, strips the pin and state and acts on them. The server also lists the current status of the analog pins. I know there may be problems with my code below as far as that functionality is concerned, but at this point I can't even get the Arduino to display a webpage. Every browser I've tried just gives me either a connection reset error or an unable to connect error. I tried various things but with no success.

I'm sort of new to the ethernet shield so any input is welcome.

Thanks!

Ben

#if ARDUINO > 18
#include <SPI.h>
#endif

#include <Ethernet.h>
#include <TextFinder.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 1, 1, 8 };

Server server(80);

void setup()
{
  Serial.begin(9600);
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.println("Ready");
}

void loop()
{
  Client client = server.available();
  if(client) {
    TextFinder finder(client);
    while (client.connected()) {
      if (client.available()) {
        int digitalRequests = 0;
        int analogRequests = 0;
        if (finder.find("GET /")) {
          while(finder.findUntil("pin", "\n\r")){
            char type = client.read();
            int pin = finder.getValue();
            int val = finder.getValue();
            if( type == 'D') {
              Serial.print("Digital Pin ");
              pinMode(pin, OUTPUT);
              digitalWrite(pin, val);
              digitalRequests++;
            }
            else if( type == 'A'){
              Serial.print("Analog Pin ");
              analogWrite(pin, val);
              analogRequests++;
            }
            else {
              Serial.print("Unexpected Type");
              Serial.print(type);
            }
            Serial.print(pin);
            Serial.print("=");
            Serial.println(val);
          }
        }
        Serial.println();
        
        client.println("HTTP/1.1 200 OK");
        client.println("Content-Type: text/html");
        client.println();
        
        client.print(digitalRequests);
        client.print(" digital pin(s) written");
        client.println("
");
        client.print(analogRequests);
        client.print(" analog pin(s) written");
        client.println("
");
        client.println("
");
        
        for (int i = 0; i < 6; i++) {
          client.print("analog input");
          client.print(i);
          client.print(" is ");
          client.print(analogRead(i));
          client.print("
");
        }
        break;
      }
    }
    delay(1);
    client.stop();
  }
}

If you have a wiznet w5100 ethernet shield, you can try the below server code to see if you can get the meta refresh page to work.

// arduino IDE 1.0
// for W5100 ethernet shield
// the IP address will be dependent on your local network/router
// port 80 is default for HTTP, but can be changed as needed
// use IP address like http://192.168.1.102:84 in your brouser
// or http://zoomkat.no-ip.com:84 with dynamic IP service
// use the \ slash to escape the " in the html
// meta refresh set for 2 seconds

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

int x=0; //set refresh counter to 0
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,102); // ip in lan
EthernetServer server(84); //server is using port 84

void setup()
{
  // start the server
  Ethernet.begin(mac, ip);
  server.begin();
}

void loop()
{
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
     while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // see if HTTP request has ended with blank line
        if (c == '\n') {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          
          //meta-refresh page every 2 seconds
          x=x+1;
          client.println("<HTML>");
          client.print("<HEAD>");
          client.print("<meta http-equiv=\"refresh\" content=\"2\">");
          client.print("<TITLE />Zoomkat's meta-refresh test</title>");
          client.print("</head>");
          client.println("<BODY>");
          client.print("Zoomkat's meta-refresh test IDE 1.0");
          client.println("
");
                    
          client.print("page refresh number ");
          client.println(x); //current refresh count
          client.println("
");
          client.println("
");
          
          client.print("Zoomkat's arduino analog input values:");
          client.println("
");
          client.println("
");
          
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(analogRead(analogChannel));
            client.println("
");
            }
           break;
          client.println("</BODY>");
          client.println("</HTML>");
         }
        }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
  }
}

Thanks for the help, zoomkat! I figured out what my problem was... a bit embarrassing to say the least. The IP address I set for my Arduino was conflicting with another on the network. Change the address and it worked immediately. I should check this things more thoroughly next time!

Thanks for your help.