Go Down

Topic: LAN server without refreshing (Read 1 time) previous topic - next topic

irab88

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?
--Ian

irab88

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)

Code: [Select]
//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><br></div>");

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

          client.println("<center><br><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><br>");
          client.println("</div>");
          client.println("<div id=\"footer\" style=\"background-color:#000099;color:#eeee00;clear:both;text-align:center;\"><br><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();
  }
}
--Ian

irab88

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

llukkari


zoomkat


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.
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Go Up