Webserver failure to communicate

Dear all
i have code as below. This thing tried on below program.

  1. Individually both functions are working fine
  2. When i put all together web browser doesn’t show any data.
#include <SPI.h>
#include <Ethernet.h>

const int SENSOR_PIN = A0;
const int SAMPLE_COUNT = 10;
const unsigned long SAMPLE_RATE = 1000UL; // every two seconds
int local_day=12;
int local_month=4;
int local_year=2014;
int local_h=12;
int local_m=12;
int local_s=12;
int LED = 3;          // led is connected to digital pin 3
int PIR = 2;          // PIR sensor is connected to digital pin 2
int LDR = 1;          // LDR sensor is connected to analog in 5
int PIRstate = 0;     // variable for PIR sensor status
float photocell = 0;  // variable for photocell (LDR) analog value
char c = 0;           // received data
char command[2] = "\0";  // command


// array to store the samples
float sample[SAMPLE_COUNT];
byte sampleIndex = 0;
float sampleAverage(void);
static int Wind_Exceed_count;
int Stow_flag=0;
float Wind_Speed;
float Wind_Kmph;

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

EthernetServer server(80);


float sampleAverage(void)
{
  float accumulator = 0;
  for (int i = 0; i < SAMPLE_COUNT; i++)
  {
    accumulator += sample[i];
  }
  return accumulator / SAMPLE_COUNT;
}

void Wind_calc()
{
  static unsigned long lastSampleTime = 0;
  unsigned long currentTime = millis();
  // check if time for new reading
  if (currentTime - lastSampleTime >= SAMPLE_RATE)
  {
    lastSampleTime = currentTime;
    int sensorValue = analogRead(SENSOR_PIN);
    float voltage = sensorValue * (5.0 / 1023.0);
    sample[sampleIndex] = voltage;
    sampleIndex++;
    if (sampleIndex == SAMPLE_COUNT)
    {
      sampleIndex = 0;
    }
    float average = sampleAverage();
    Wind_Speed = (6 * average);
    Wind_Kmph = 3.6 * Wind_Speed;

  }
}

void setup()
{
  pinMode(8,OUTPUT);
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
 
}

void loop()
{
  Wind_calc();
  Ethernet_Control();
  
}


void Ethernet_Control()
{
  EthernetClient client = server.available();
  // detect if current is the first line
  boolean current_line_is_first = true;

  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = 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 (c == '\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();

          // auto reload webpage every 5 second
          client.println("<META HTTP-EQUIV=REFRESH CONTENT=5 URL=>");

          // webpage title
          client.println("<center><p><h1>NORDIC INDIA SOLAR WEB APPPLICATION V1.0</h1></p><center><hr>
");
          client.print("<p><h2>DATE: = <font color=indigo>");
          client.print(local_day);
          client.print("/");
          client.print(local_month);
          client.print("/");
          client.print(local_year); 
          client.println("</font></h2></p>");
          client.print("<p><h2>TIME: = <font color=indigo>");
          client.print(local_h);
          client.print("/");
          client.print(local_m);
          client.print("/");
          client.print(local_s);
          client.println("</font></h2></p>");
          
          client.print(Wind_Speed); 
           client.println("</font></h2></p>");
           client.print("<p><h2>WIND_SPEED KMPH: = <font color=indigo>");  
           client.print(Wind_Kmph); 
           client.println("</font></h2></p>");



          // read digital pin 13 for the state of PIR sensor
          PIRstate = digitalRead(8);
          if (PIRstate == HIGH) { // PIR sensor detected movement
            client.println("<p><h2><font color=red>Motion Detected!</font></h2></p>");
          }
          else { // No movement is detected
            client.println("<p><h2><font color=green>No Movement</font></h2></p>"); 
          }  

          // button functions
          client.println("<form  method=get name=form>");
          client.println("<button name=b value=1 type=submit style=height:80px;width:150px>LED On</button>");
          client.println("<button name=b value=2 type=submit style=height:80px;width:150px>LED Off</button>");
          client.println("</form>
");

          // webpage footer
          client.println("<hr><center><a href=http://www.robothead2toe.com.my>Robot.Head to Toe</a>
");
          client.println("<p>P.S.: This page will automatically refresh every 5 seconds.</p></center>");

          break;
        }
        if (c == '\n') {
          // we're starting a new line
          current_line_is_first = false;
          current_line_is_blank = true;
        } 
        else if (c != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;
        }
        // get the first http request
        if (current_line_is_first && c == '=') {
          for (int i = 0; i < 1; i++) {
            c = client.read();
            command[i] = c;
          }
          // LED control
          if (!strcmp(command, "1")) {
            digitalWrite(LED, HIGH);
          }
          else if (!strcmp(command, "2")) {
            digitalWrite(LED, LOW);
          }
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    client.stop();
  }
}

You still haven't come to terms with the fact that your Arduino doesn't have 2 terrabytes of memory, I see.

Server code that demonstrates the use of the F() macro on static character strings that saves memory.

// zoomkat's meta refresh data frame test page 8/17/13
// use http://192.168.1.102:84 in your brouser for main page
// http://192.168.1.102:84/data static data page
// http://192.168.1.102:84/datastart meta refresh data page
// for use with W5100 based ethernet shields
// set the refresh rate to 0 for fastest update
// use STOP for single data updates

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

const int analogInPin0 = A0;
const int analogInPin1 = A1;
const int analogInPin2 = A2;
const int analogInPin3 = A3;
const int analogInPin4 = A4;
const int analogInPin5 = A5;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // arduino 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
unsigned long int x=0; //set refresh counter to 0
String readString; 

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

void setup(){
  Serial.begin(9600);
    // disable SD SPI if memory card in the uSD slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();
  Serial.println("meta refresh data frame test 8/17/13"); // so I can keep track of what is loaded
}

void loop(){
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
         if (readString.length() < 100) {
          readString += c; 
         } 
        //check if HTTP request has ended
        if (c == '\n') {

          //check get atring received
          Serial.println(readString);

          //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"));

          //generate data page
          if(readString.indexOf("data") >0) {  //checks for "data" page
            x=x+1; //page upload counter
            client.print(F("<HTML><HEAD>"));
            //meta-refresh page every 1 seconds if "datastart" page
            if(readString.indexOf("datastart") >0) client.print(F("<meta http-equiv='refresh' content='1'>")); 
            //meta-refresh 0 for fast data
            if(readString.indexOf("datafast") >0) client.print(F("<meta http-equiv='refresh' content='0'>")); 
            client.print(F("<title>Zoomkat's meta-refresh test</title></head><BODY>
"));
            client.print(F("page refresh number: "));
            client.print(x); //current refresh count
            client.print(F("

"));
            
              //output the value of each analog input pin
            client.print(F("analog input0 is: "));
            client.print(analogRead(analogInPin0));
            
            client.print(F("
analog input1 is: "));
            client.print(analogRead(analogInPin1));
                        
            client.print(F("
analog input2 is: "));
            client.print(analogRead(analogInPin2));
            
            client.print(F("
analog input3 is: "));
            client.print(analogRead(analogInPin3));
                                    
            client.print(F("
analog input4 is: "));
            client.print(analogRead(analogInPin4));
            
            client.print(F("
analog input5 is: "));
            client.print(analogRead(analogInPin5));
            client.print(F("
</BODY></HTML>"));
           }
          //generate main page with iframe
          else
          {
            client.print(F("<HTML><HEAD><TITLE>Zoomkat's frame refresh test</TITLE></HEAD>"
            "Zoomkat's Arduino frame meta refresh test 8/17/13"
            "

Arduino analog input data frame:
"
            "&nbsp;&nbsp;<a href='/datastart' target='DataBox' title=''yy''>META-REFRESH</a>"
            "&nbsp;&nbsp;&nbsp;&nbsp;<a href='/data' target='DataBox' title=''xx''>SINGLE-STOP</a>"
            "&nbsp;&nbsp;&nbsp;&nbsp;<a href='/datafast' target='DataBox' title=''zz''>FAST-DATA</a>
"
            "<iframe src='/data' width='350' height='250' name='DataBox'>"
            "</iframe>
</HTML>"));
          }
          delay(1);
          //stopping client
          client.stop();
          //clearing string for next read
          readString="";
        }
      }
    }
  }
}