LAN server without refreshing

the setup:
network shield on top, mega on the bottom, 32 i/o ports in-use (as outputs)

the dilemma:
every time a button on the "webpage" is pressed to control an i/o port, the entire page is refreshed/reloaded. normally that wouldn't be an issue, but my network seems to act weird. i have a video server that works like it should; streaming in real-time. but each time the arduino webpage is loaded, it's a crap shoot weather the whole thing loads all the way or not. in ie, it'll load some and stop loading after showing some code on-screen. on firefox, it times out with an error message mostly. on chrome, it loads what it can; sometimes just the head, sometimes the whole thing. i can still use the functions, but it's not what i programmed it to do.
(also: locally, it works perfectly. remotely, it has the problems)

i'll get code up in a bit. any alternatives to keeping the connection open full-time, or making sure the whole page always loads?

places for 8 "robots" each with 4 functions. each robot is different, and the controlls are all different (they all have power, standby, up, and down, but how each controll is opperated is different)

//updated 2012-11-28

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

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 
  192, 1, 1, 102 };
byte gateway[] = { 
  192, 1, 1, 1 };
byte subnet[] = { 
  255, 255, 255, 0 };


int rControl[8][4] = {
  {
    02,03,05,06        }
  ,
  {
    22,23,24,25        }
  ,
  {
    26,27,28,29        }
  ,
  {
    30,31,32,33        }
  ,
  {
    34,35,36,37        }
  ,
  {
    38,39,40,41        }
  ,
  {
    42,43,44,45        }
  ,
  {
    46,47,48,49        }
};


//make sure this list matches the switch/case below!!!
String rName[8] = {
  "BOB","BOBBY","JACK","empty","empty","empty","empty","empty"};
String rFunc[4] = {
  "POWER","STANDBY","UP","DOWN"};
String rPower[8] = {
  "off","off","off","off","off","off","off","off"};

String tempStr;

int intQuestion;
int intEquals;

String inString = String(35);

String Led;

EthernetServer server(80);
String data;

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

  Ethernet.begin(mac, ip);
  //Ethernet.begin(mac, ip,gateway,subnet); 
  server.begin();

  for (int r = 0; r < 8; r++){
    for (int c = 0; c < 4; c++){
      pinMode(rControl[r][c], OUTPUT);
    }
  }

  //initial power state (BOB=LOW; JACK=HIGH;)
  digitalWrite(rControl[0][0], LOW);
  digitalWrite(rControl[1][0], LOW);
  digitalWrite(rControl[2][0], HIGH);
  digitalWrite(rControl[3][0], HIGH);
  digitalWrite(rControl[4][0], LOW);
  digitalWrite(rControl[5][0], LOW);
  digitalWrite(rControl[6][0], HIGH);
  digitalWrite(rControl[7][0], HIGH);

  Serial.println("Serial READY");
  Serial.println("Ethernet READY");
  Serial.println("Server READY");
}

void loop()
{
  EthernetClient client = server.available();

  if(client){
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    while (client.connected()) {

      if(client.available()) {

        char cl = client.read();
        // if we've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so we can send a reply
        if (inString.length() < 35) {
          inString.concat(cl);
        } 
        if (cl == '\n' && current_line_is_blank) {

          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<html><head><title>TINY robot control</title></head><body bgcolor=#000099><form method=get>");
          client.println("<div id=\"container\">");
          client.println("<div id=\"header\" style=\"background-color:#000099;\">");
          client.println("<font size=10 face=\"britannic bold\" style=\"color:#eeee00;margin-bottom:0;\"><center><i>The TITle goes here.</i></center></font>");
          client.println("<font face=\"arial\" style=\"color:#dddd00;\"><center>lots of robots, so little time</center></font>
</div>");

          
          client.println("<div id=\"content\" style=\"background-color:#EEEEEE;float:left;width:100%;\">");

          client.println("<center>
<table border=\"1\">");

          Serial.println(inString);
          //entire loop starts here
          for (int r = 0; r < 8; r++){
            client.println("<tr>");
            client.println("<td>"+String(rName[r])+"</td>");
            for (int c = 0; c < 4; c++){

              intQuestion = inString.indexOf("?") +1;
              intEquals = inString.indexOf("=");
              //check the incomming string for control number
              if(inString.substring(intQuestion,intEquals) == String(rControl[r][c])){
                Serial.println(rControl[r][c]);
                //Serial.println(inString.substring(intQuestion,intEquals) + "vvvv");

                //match the control functions to the individual radars
                if(rName[r] == "BOB"){
                  //check if it's the power button
                  if(c == 0){
                    //power button switch
                    if(rPower[r] == "off"){
                      digitalWrite(rControl[r][c], HIGH);
                      rPower[r] = "ON";
                    }
                    else if(rPower[r] == "ON"){
                      digitalWrite(rControl[r][c], LOW);
                      rPower[r] = "off";
                    }
                  }
                  else{
                    digitalWrite(rControl[r][c], HIGH);
                    delay(50);
                    digitalWrite(rControl[r][c], LOW);
                  }
                }
                else if(rName[r] == "BOBBY"){
                  //check if it's the power button
                  if(c == 0){
                    //power button switch
                    if(rPower[r] == "off"){
                      digitalWrite(rControl[r][c], HIGH);
                      rPower[r] = "ON";
                    }
                    else if(rPower[r] == "ON"){
                      digitalWrite(rControl[r][c], LOW);
                      rPower[r] = "off";
                    }
                  }
                  else{
                    digitalWrite(rControl[r][c], HIGH);
                    delay(50);
                    digitalWrite(rControl[r][c], LOW);
                  }
                }
                else if(rName[r] == "JACK"){
                  //check if it's the power button
                  if(c == 0){
                    //power button switch
                    if(rPower[r] == "off"){
                      digitalWrite(rControl[r][c], LOW);
                      rPower[r] = "ON";
                      delay(50);
                      digitalWrite(rControl[r][c], HIGH);
                      delay(9500);
                      digitalWrite(rControl[r][c], LOW);
                      delay(50);
                      digitalWrite(rControl[r][c], HIGH);
                    }
                    else if(rPower[r] == "ON"){
                      digitalWrite(rControl[r][c], LOW);
                      rPower[r] = "off";
                      delay(5000);
                      digitalWrite(rControl[r][c], HIGH);
                    }
                  }
                  //check if it's the standby button
                  else if(c == 1){
                    digitalWrite(rControl[r][c-1], LOW);
                    delay(70);
                    digitalWrite(rControl[r][c-1], HIGH);
                    delay(70);
                    digitalWrite(rControl[r][c], HIGH);
                    delay(70);
                    digitalWrite(rControl[r][c], LOW);
                  }
                  else{
                    digitalWrite(rControl[r][c], HIGH);
                    delay(50);
                    digitalWrite(rControl[r][c], LOW);
                  }
                }

              }              
              client.println("<td><input type=submit name="+String(rControl[r][c])+" value="+String(rFunc[c])+"></td>");
            }
            if(rPower[r] == "ON"){
              client.println("<td bgcolor=#00ff00 width=30><center>"+rPower[r]+"</center></td>");
            }
             else{
              client.println("<td bgcolor=#ff0000 width=30><center>"+rPower[r]+"</center></td>");
             }
            client.println("</tr>");
          }
          //entire loop ends here

          client.println("</table></center>
");
          client.println("</div>");
          client.println("<div id=\"footer\" style=\"background-color:#000099;color:#eeee00;clear:both;text-align:center;\">
<font face=\"arial\">footer placeholder</face></div>");

          client.println("</div></from></html></body>");
          break;
        }
        if (cl == '\n') {
          // we're starting a new line
          current_line_is_blank = true;
        } 
        else if (cl != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    inString = "";
    client.stop();
  }
}

nothin'? so it's just a way of life, then?

I'm not sure but has the String been fixed yet?

http://code.google.com/p/arduino/issues/detail?id=857

Could it be that?

irab88:
nothin'? so it's just a way of life, then?

192, 1, 1, 102 looks strange for a lan ip address (I'm use to 192.168.1.x). You might try putting the static text in the F() macro, and don't reload the page.

yeah, the ip address is what i use around here. it works, so i'm not worried.

what you suggest sounds good. i'll look up some info on it, but would you happen to have any links or examples you could point me to? like i said, i'll be searching as well. thanks a bunch

Simple web control test code for non refreshing the main page.

//zoomkat 12-8-11
//simple button GET with iframe 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 
//address will look like http://192.168.1.102:84/ when submited
//for use with W5100 based ethernet shields

#include <SD.h> //for SD card use
#include <SPI.h>
#include <Ethernet.h>

#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

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

String readString; 

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

void setup(){

  //enable serial data print 
  Serial.begin(9600); 
  Serial.println("server LED test 1.0"); // so I can keep track of what is loaded

  // disable w5100 while setting up SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);
  Serial.print("Starting SD..");
  if(!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok");
  
  pinMode(5, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();

  myservo.write(90); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo co

}

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);
        } 

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

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging 

          //now output HTML data header
             if(readString.indexOf('?') >=0) { //don't send new page
               client.println("HTTP/1.1 204 Zoomkat");
               client.println();
               client.println();  
             }
             else {
          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
          client.println();

          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>Arduino GET test page</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");

          client.println("<H1>Zoomkat's simple Arduino button</H1>");
          
          client.println("<a href=\"/?on\" target=\"inlineframe\">ON</a>"); 
          client.println("<a href=\"/?off\" target=\"inlineframe\">OFF</a>"); 

          //client.println("<IFRAME name=inlineframe src=\"res://D:/WINDOWS/dnserror.htm\" width=1 height=1\">");
          client.println("<IFRAME name=inlineframe style=\"display:none\" >");          
          client.println("</IFRAME>");

          client.println("</BODY>");
          client.println("</HTML>");
             }

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

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

        }
      }
    }
  }
}

thank you! perfect. now i just need to get it to work with buttons in lieu of links.