Ethernet Shield Stop sending web page

Hi

I had a simple web server set up yesterday with the original code below.

It was working fine on my local IP and from my external IP address

Today, I've modified the code, but only taking unwanted HTML code out and changing the button sizes.

Now it won't display the page.

I've tried the examples, and they work ok. Send a ping from CMD works fine, so I know its not cable or router issues.

Original code

#include <SPI.h>
#include <Ethernet.h> // Initialize the libraries.
 
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //I left the MAC address and IP address blank.
byte ip[] = { 192,168,0,21 };                     // You will want to fill these in with your MAC and IP address.
 
EthernetServer server(XXXX); // Assigning the port forwarded number. It's almost always 80.
 
String readString; // We will be using strings to keep track of things.
int val;    // Using val as a variable for the PIR status.

 
//////////////////////
 
void setup(){
 
  pinMode(2, OUTPUT);
 
  Ethernet.begin(mac, ip);

}
 
void loop(){
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {                     // This is all where we start up the server and strings.
        char c = client.read();                     
        if (readString.length() < 100) {
          readString += c;
        } 
        if (c == '\n') {
          Serial.println(readString);                      // And here we begin including the HTML
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<hmtl>");
client.println("<head>");
client.println("ARDUINO PAGE");
client.println("</head>");
client.println("<title>");
client.println("ARDUINO + ETHERNET Page");
client.println("</title>");
client.println("<body bgcolor=black>");
client.println("<font color=white>");
client.println("<meta http-equiv=\"refresh\" content=\"4\">"); // This is used to refresh the page so
client.println("<center>");                                      // we can see if there is Motion or not.
client.println("<b>");
client.println("Greetings! Here you will find a somewhat interactive page served up by my Arduino!");
client.println("
");
client.println("As well, you can interact with my Arduino! It's pretty basic, and you really can't see it,");
client.println("
");
client.println("but as you press a button, you turn on or off an LED or move a Servo! Have fun!");
client.println("</b>");
client.println("<p>");
client.println("<table border=0 width=200>");
client.println("<tr>");
client.println("<td align=center>");
client.println("<font color=white>");
client.println("The Temperature is:");
client.println("</td>");
client.println("</tr>");
client.println("<tr>");
client.println("<td align=center>");
client.println("<font color = turquoise size=10>");
//int temp = (((5*analogRead(5)*100/1024)*1.8)+32);     // This replaces the 00 with a temperature in F.
//client.println(temp);
client.println("* F");
client.println("</td>");
client.println("</tr>");
client.println("</table>");
client.println("<p>");
client.println("<FORM>");
client.println("<INPUT type=button value=LED1-ON onClick=window.location='/?lighton1\'>");
client.println("<INPUT type=button value=LED1-OFF onClick=window.location='/?lightoff1\'>");
client.println("</FORM>");   // Above and below you'll see that when we click on a button, it adds a little snippet
                             // to the end of the URL. The Arduino watches for this and acts accordingly.




client.println("</center>");
client.println("</font>");
client.println("</body>");
client.println("</html>");
 
          delay(1);
  	  
          if(readString.indexOf("?lighton") >0)     // these are the snippets the Arduino is watching for.
          {
            digitalWrite(2, HIGH);
          }
          else{
          if(readString.indexOf("?lightoff") >0)
          {
            digitalWrite(2, LOW);
          }
    
          }
          readString="";
          client.stop();            // End of session.
 
        }
      }
    }
  }
}

Modified code:

#include <SPI.h>
#include <Ethernet.h> // Initialize the libraries.
 
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //I left the MAC address and IP address blank.
byte ip[] = { 192,168,0,21 };                     // You will want to fill these in with your MAC and IP address.
 
EthernetServer server(XXXX); // Assigning the port forwarded number. It's almost always 80.
 
String readString; // We will be using strings to keep track of things.
int val;    // Using val as a variable for the PIR status.

 
//////////////////////
 
void setup(){
 
  pinMode(2, OUTPUT);
 
  Ethernet.begin(mac, ip);

}
 
void loop(){
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {                     // This is all where we start up the server and strings.
        char c = client.read();                     
        if (readString.length() < 100) {
          readString += c;
        } 
        if (c == '\n') {
          Serial.println(readString);                      // And here we begin including the HTML
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<hmtl>");
client.println("<head>");
client.println("ARDUINO PAGE");
client.println("</head>");
client.println("<title>");
client.println("ARDUINO + ETHERNET Page");
client.println("</title>");
client.println("<body bgcolor=black>");
client.println("<font color=white>");
client.println("<meta http-equiv=\"refresh\" content=\"4\">"); // This is used to refresh the page so
client.println("<center>");                                      // we can see if there is Motion or not.
client.println("<b>");
client.println("Simple LED Switch");
client.println("
");
client.println("<FORM>");
client.println("<INPUT type=button value=LED1-ON style='width: 200px; height: 60px' onClick=window.location='/?lighton1\'>");
client.println("<INPUT type=button value=LED1-OFF style='width: 200px; height: 60px' onClick=window.location='/?lightoff1\'>");
client.println("</FORM>");   // Above and below you'll see that when we click on a button, it adds a little snippet
                             // to the end of the URL. The Arduino watches for this and acts accordingly.




client.println("</center>");
client.println("</font>");
client.println("</body>");
client.println("</html>");
 
          delay(1);
  	  
          if(readString.indexOf("?lighton") >0)     // these are the snippets the Arduino is watching for.
          {
            digitalWrite(2, HIGH);
          }
          else{
          if(readString.indexOf("?lightoff") >0)
          {
            digitalWrite(2, LOW);
          }
    
          }
          readString="";
          client.stop();            // End of session.
 
        }
      }
    }
  }
}

Yes the port isn't set to XXXX in reality.

Any ideas?

Solved

For some reason it didn't like my assigned port. It was the same as yesterdays.

Now I've changed it, its fine.

Don't know why that would happen tho

I don't see a server.begin() call in setup.

Today, I've modified the code, but only taking unwanted HTML code out and changing the button sizes.

If your changes actually increased the static character content of your code, you may have run out of memory. Use the F() macro for all your static text.

Thanks guys.

I managed to get it working after moving port numbers.

I'm not sure why this would make a difference as the port was open.

Now going to try and build a better and more involved page to control more stuff!

I need try work out how I can set the GUI of the page to read the current status of the pins. But thats probably a question for a different section.

Feb 02, 2014

Hello:

I am having difficulty using the Arduino Web Client Code (many possible examples). I used some ethernet shields about 4 years ago, and had good luck with them (they could pull 'www.google.com' in). I bought some more or less newer ones from Radio Shack recently, and have tried to use some of the newer releases of code to bring in the same result, and am having very poor results. I'm not really suspicious of the radio shack hardware, maybe I should be. Am I asking this question in the wrong part of the forum??? Can anyone help??? I've tinkered with many of the variables like IP, Mac, and on and on, and can't get the boards to pull in www.google.com (or anything else for that matter). I don't know what I'm doing wrong.