Pages: [1]   Go Down
Author Topic: Web Page wont load  (Read 360 times)
0 Members and 1 Guest are viewing this topic.
Ontario Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to ceate a program to control my sprinkler system from the internet but having trouble with the web page loading once I have set all the outputs. The code that I have posted looks good on the web page as it stands and works except for the last 3 control blocks. The problem happens once I get beyond the first 4 control blocks of code which work fine. If I change the Led pin control to match the statments in the HTML code for the last 3 control blocks the page will no longer load. If Ieave the value set to what it is in the posted code it loads no problem but does not control the led I want. Is there a limit for the Arduino Uno in this area?? It compiles fine at 14,032 bytes.
Code:
#include <Ethernet.h>
#include <SPI.h>
boolean reading = false;
int temperaturePin = 0;
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,1,66 };
static char baseurl[]="http://192.168.1.66/";
EthernetServer server(80);


void setup(){
  //Pins 10,11,12 & 13 are used by the ethernet shield
//  Serial.begin(9600);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  Ethernet.begin(mac, ip);
  server.begin();
//  Serial.println(Ethernet.localIP());
}

void loop()
{
  // listen for incoming clients, and process qequest.
  checkForClient();             
}
float getVoltage(int pin){
return (analogRead(pin) * .004882814);
             
}

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

  if (client) {

    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    boolean sentHeader = false;

    while (client.connected()) {
      if (client.available()) {
        if(!sentHeader){
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
//------------------HTML-------------------------------
//client.print("<html><head>");
//client.print("<title>Arduino Webserver Darryl</title>");
//client.println("</head>");
client.print("<body bgcolor='#80bfff'>");
//client.println("<br><hr />");
//client.println("Sprinkler & Pool Temperature");
//client.println("<hr /><br>");
{
int  analogChannel = 0; 
int sensorReading = analogRead(analogChannel);
float temperature = getVoltage(temperaturePin);
temperature = (temperature - .5) * 100;
client.print("POOL TEMPERATURE ");
client.print(" is ");
client.print(temperature);
client.println("<br />");
          }                       
//-------------------Control code Front North------------
client.println("<table border='1' width='50%' cellpadding='5'>");
client.println("<tr bgColor='#222222'>");
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>Front N Sprinkler<br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=1 value='Turn On'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=0 value='Turn Off'></form></td>");

 //-------------------Control code Front South------------         
client.println("<table border='1' width='50%' cellpadding='5'>");
client.println("<tr bgColor='#222222'>");
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>Front S Sprinkler<br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=3 value='Turn On'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=2 value='Turn Off'></form></td>");

 //-------------------Control code Front Centre------------
client.println("<table border='1' width='50%' cellpadding='5'>");
client.println("<tr bgColor='#222222'>");
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>Front C Sprinkler<br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=5 value='Turn On'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=4 value='Turn Off'></form></td>");       
       
//-------------------Control code Back South------------       
client.println("<table border='1' width='50%' cellpadding='5'>");
client.println("<tr bgColor='#222222'>");
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>Back_N Sprinkler<br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=7 value='Turn On'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=6 value='Turn Off'></form></td>");       
               
//-------------------Control code Back North------------         
client.println("<table border='1' width='50%' cellpadding='5'>");
client.println("<tr bgColor='#222222'>");
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>Back_S Sprinkler<br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=7 value='Turn On'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=6 value='Turn Off'></form></td>");       
//client.println("<hr /><br>");                           
//-------------------Control code Pool Lights North------------         
client.println("<table border='1' width='50%' cellpadding='5'>");
client.println("<tr bgColor='#222222'>");
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>Pool Lights <br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=7 value='Turn On'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=6 value='Turn Off'></form></td>");
//client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=6 value='Turn Off'></form></td>");
//client.println("<hr /><br>");
//-------------------Control code Pool Lights South------------
client.println("<table border='1' width='50%' cellpadding='5'>");
client.println("<tr bgColor='#222222'>");
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>Pool Lights <br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=7 value='Turn On'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=6 value='Turn Off'></form></td>");
//client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=6 value='Turn Off'></form></td>");
//client.println("<hr /><br>");                                     
          // add a meta refresh tag, so the browser pulls again every 5 seconds:
          client.println("<meta http-equiv=\"refresh\" content=\"20\">");
          // output the value of each analog input pin
         
         
          }     
          sentHeader = true;
        }

        char c = client.read();
        if(reading && c == ' ') reading = false;
        if(c == '?') reading = true; //found the ?, begin reading the info
        if(reading){
         
          //control for pin 4
          if(c == '0') {
            digitalWrite(4, LOW);
            break;
          }
           if(c == '1') {
            digitalWrite(4, HIGH);
            break;
           }
             if(c == '2') {
            digitalWrite(5, LOW);
            break;
           }
          if(c == '3') {
            digitalWrite(5, HIGH);
            break;
          }
           if(c == '4') {
            digitalWrite(6, LOW);
            break;
           }
            if(c == '5') {
            digitalWrite(6, HIGH);
            break;
           }
            if(c == '6') {
            digitalWrite(7, LOW);
            break;
           }
           if(c == '7') {
            digitalWrite(7, HIGH);
            break;
           }
            if(c == '8') {
            digitalWrite(8, LOW);
            break;
           }
           if(c == '9') {
            digitalWrite(8, HIGH);
            break;
           }
        }
         if (c == '\n' && currentLineIsBlank)  break;
         if (c == '\n') {
          currentLineIsBlank = true;
        }else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    delay(1); // give the web browser time to receive the data
    client.stop(); // close the connection:
  }

Logged

0
Offline Offline
Tesla Member
***
Karma: 144
Posts: 9612
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to use the F() macro like below on the static html text to save memory.

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

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

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

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Ontario Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks so much Zoomkat that works great!! So what does the F statement do?
Logged

Chicago
Offline Offline
Full Member
***
Karma: 0
Posts: 113
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://playground.arduino.cc/Main/Printf
Look in the middle of the page.
Logged

Pages: [1]   Go Up
Jump to: