I can't connect to my Etherten is something wrong with the code or the browser?

The code compiles in arduino 1.0 and uploads but when i connect to it through my browsers(firefox and internet explorer) it says internet exploerer cannot display the webpage and on firefox its just blank.

here is the code

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

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {
  192,168,2, 77 };

EthernetServer server(80);


int LED = 15;//Analog pin 5 (yes it works as a digital pin too)

void setup()
{
  Ethernet.begin(mac, ip);
  server.begin();
  pinMode(LED, OUTPUT);

}
#define BUFSIZ 100    //Buffer size for getting data
char clientline[BUFSIZ];  //string that will contain command data
int index = 0;  //clientline index
void loop()
{
  index=0;  //reset the clientline index
  EthernetClient client = server.available();
  if (client) {
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if(index<BUFSIZ)  //Only add data if the buffer isn't full.
        {
          clientline[index]=c;
          index++;
        }
        if (c == '\n' && currentLineIsBlank)
        {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<h1><center>Arduino Home Automation</h1></center><br><center><form method=get action=/?><input type=radio name=L1 value=1>Relay1 On<input type=radio name=L1 value=0>Relay1 Off<br><input type=submit value=submit></form></center>");
         break;
        }
        if (c == '\n') {
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
        if(strstr(clientline,"/?L1=1")!=0) {  //look for the command to turn the led on.
          digitalWrite(LED, 1);  //turn the led on
        } else if(strstr(clientline,"/?L1=0")!=0) {  //look for command to turn led off.
          digitalWrite(LED, 0);  //turn led off
        }
       
    delay(1);
    client.stop();
      }
    }
  }
}

Thanks in advance

2 answers
Jan 27, 2012. 7:25 PMKiwi_John says:
I had some similar problems, solved by plugging in an external power supply as well as the USB cable from my computer.
Dec 11, 2011. 3:42 PMDeez2009 says:
I had a similar problem with an Uno and Ethernet Shield, and after pulling all my hair out, i decided to recompile and upload using .22 instead of .23 of the IDE, and that solved my problem. Have you tried that?


Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!