web server code

Hello people!
I got a really tricky question i think!

I have an ethernet shield on my arduino and I tried something like that:

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

#define TDIECI 1000
#define TNOVAN 50000

int coordinata=0;
boolean is_moving=false;
boolean is_open=false;
char buffer[3];
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 111 };
byte gateway[] = { 192, 168, 1, 1 }; 
byte subnet[] = { 255, 255, 255, 0 }; 
EthernetServer server(80);

String readString;
byte out_1 = 8;
byte out_2 = 9;

void calcolaesposta (int coord){
  ;
}

void setup() { 
  Ethernet.begin(mac, ip);
  pinMode(out_1, OUTPUT);
  pinMode(out_2, OUTPUT);     
}
 
void loop() { 
  EthernetClient  client = server.available();
  if (client) {
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) { 
        char c = client.read();
        readString.concat(c);   
        if (c == '\n' && currentLineIsBlank) {
          if(readString.indexOf("?") > -1) {
            if(readString.indexOf("sx") > 0)   {digitalWrite(out_1, HIGH); is_moving=true;}
            if(readString.indexOf("dx") > 0)   {digitalWrite(out_2, HIGH); is_moving=true;}          
            if(readString.indexOf("stop") > 0) {digitalWrite(out_2, LOW); digitalWrite(out_1, LOW); is_moving=false;}     
            if(readString.indexOf("sx10") > 0) {digitalWrite(out_1, HIGH); delay(TDIECI); digitalWrite(out_1, LOW);}
            if(readString.indexOf("dx10") > 0) {digitalWrite(out_2, HIGH); delay(TDIECI); digitalWrite(out_2, LOW);}
            if(readString.indexOf("sx90") > 0) {digitalWrite(out_1, HIGH); delay(TNOVAN); digitalWrite(out_1, LOW);}
            if(readString.indexOf("dx90") > 0) {digitalWrite(out_2, HIGH); delay(TNOVAN); digitalWrite(out_2, LOW);}
            if(readString.indexOf("apri") > 0) {is_open=true;}
            if(readString.indexOf("chiudi") > 0) {is_open=false;}
            if(readString.indexOf("coord") > 0)  {
              int poscoord=readString.indexOf("coord");
              readString.substring(poscoord, poscoord+3).toCharArray(buffer, 3);
              coordinata=atoi(buffer);
              calcolaesposta(coordinata);
            }
          }   
         
          //  PAGINA HTML      
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.print("<html><head><title>.::Museo del Bali - Arduino Autodome::.</title>");
          client.print("<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'></head>");
        
          client.print("<body><center><h1>Dome Automation</h1><hr><h3>Museo del Bali</h3>
<h4>SPOSTAMENTO CUPOLA</h4>");
        
          client.print("<table border=\"5\" cellspacing=\"3\" cellpadding=\"5\">");
          client.print("<tr><td><span>SPOSTAMENTO SX</span></td><td><center>STOP</center></td><td>SPOSTAMENTO DX</td></tr>");
          if (!is_moving) client.print("<tr><td colspan=\"3\" bgcolor=#00FF00><center>CUPOLA FERMA</center></td></tr>");
          if (is_moving) client.print("<tr><td colspan=\"3\" bgcolor=#FF0000><center>CUPOLA IN MOVIMENTO</center></td></tr>");
          client.print("<tr><td><center><input type=\"button\" style=\"width:120px; height:120px\" value=\"Start sx\" onclick =\" location.href='/?sx'\"></center></td>");  
          client.print("<td><center><input type=\"button\" value=\"STOP\" onclick =\" location.href='/?stop'\"></center></td>");
          client.print("<td><center><input type=\"button\" style=\"width:120px; height:120px\" value=\"Start dx\" onclick =\" location.href='/?dx'\"></center></td></tr>");   
             client.print("<tr><td><center><input type=\"button\" style=\"width:120px; height:120px\" value=\"Start sx\" onclick =\" location.href='/?sx'\"></center></td>");  
             client.print("<td></td>");
             client.print("<td><center><input type=\"button\" style=\"width:120px; height:120px\" value=\"Start dx\" onclick =\" location.href='/?dx'\"></center></td></tr>");
             client.print("<tr><td><center><input type=\"button\" style=\"width:120px; height:120px\" value=\"Start sx\" onclick =\" location.href='/?sx'\"></center></td>");  
             client.print("<td></td>");
             client.print("<td><center><input type=\"button\" style=\"width:120px; height:120px\" value=\"Start dx\" onclick =\" location.href='/?dx'\"></center></td></tr>");
          /*client.print("<tr><form method=get><td colspan=\"2\">Coordinata stella:</td><td><center><input size=\"15\" value=\"\" name=coord STYLE=\"background-color:#FCFCFC\">");
          client.print("<input name=\"S\" type=\"submit\" value=\"Vai\"></from></center></td></tr>"); */
          client.print("</table>");
          client.print("

<h4>APERTURA CUPOLA</h4><table border=\"3\" cellspacing=\"3\" cellpadding=\"8\">");
          client.print("<tr><td><center><input type=\"button\" style=\"width:50px; height:50px\" value=\"Apri\" onclick =\" location.href='/?apri'\"></center></td>");  
          if (!is_open) client.print("<td bgcolor=#FF0000><center>CHIUSO</center></td>");
          if (is_open) client.print("<td bgcolor=#00FF00><center>APERTO</center></td>");
          client.print("<td><center><input type=\"button\" style=\"width:50px; height:50px\" value=\"Chiudi\" onclick =\" location.href='/?chiudi'\"></center></td></tr></table></center>");
          client.print("
<p align=right> Powered by Arduino
Coded by Michelangelo
Supported by Peppe</p>");
          client.println("</body></html>");
          readString="";
        
           delay(20);
           client.flush();
           client.stop(); 
        }
      }
    }
  }
}

wich works;
instead just changing the caption of a button like:

client.print("<tr><td><center><input type=\"button\" style=\"width:120px; height:120px\" value=\"90 sx\" onclick =\" location.href='/?sx'\"></center></td>");

would not work!!!
The only difference is that of the caption of two buttons!
In the first case I can load the webpage in a browser
In the second case it just freeze

I do not know what it have to do with that, but I see that in the first case a nmap of the arduino IP gives back port 80 opened
in the second case a nmap diges no port opened!
Isn't it in the setup() function the opening of ports?
Is there something very strange or is it normal?

Thank you

mic

My guess is you are running out of SRAM. Use the F() function to keep your static strings (and you have a bunch!) in program memory. Here is an example using the first two lines of your response. Do this to the rest of those static strings in your response.

          client.println(F("HTTP/1.1 200 OK"));
          client.println(F("Content-Type: text/html"));

The below test code might be of interest as way to bundle static text lines using the F() macro in a single client.print.

//zoomkat 8-17-13
//web LED code
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html (or use ') 
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields
//turns pin 5 on/off

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

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 
  192, 168, 1, 102 }; // arduino server ip in lan
byte gateway[] = { 
  192, 168, 1, 1 }; // internet access via router gateway
byte subnet[] = { 
  255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //arduino server port

String readString; 

//////////////////////

void setup(){

  pinMode(5, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

  //enable serial data print 
  Serial.begin(9600); 
  Serial.println("servertest1"); // so I can keep track of what is loaded
}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string 
          readString += c; 
          Serial.print(c); //print what server receives to serial monitor
        } 

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString);

          //now output HTML data header

          //client.println("HTTP/1.1 200 OK");
          //client.println("Content-Type: text/html");
          //client.println();
          
          //client.print(F("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));


          client.print(F("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"
            "<HTML><HEAD><TITLE>Arduino GET test page</TITLE>"
            "</HEAD><BODY><H1>Zoomkat's simple Arduino button</H1>"
            "<a href='/?on'>ON</a>&nbsp;<a href='/?off'>OFF</a></BODY></HTML>"));

          delay(1);
          //stopping client
          client.stop();

          /////////////////////
          if(readString.indexOf("on") >0)//checks for on
          {
            digitalWrite(5, HIGH);    // set pin 5 high
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            digitalWrite(5, LOW);    // set pin 5 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}