Go Down

Topic: Problems with my webserver (Read 1 time) previous topic - next topic

Feb 27, 2011, 12:58 am Last Edit: Feb 27, 2011, 01:03 am by prozorianu Reason: 1
Hi!
I built a code for Arduino + Ethernet Shield ... Relay webserver or Led webserver- works well but in my webpage apears some errors .....
My page does not load completely

This is my code
Code: [Select]
//*******************************

#include <SPI.h>
#include <Ethernet.h>
#include <avr/pgmspace.h>



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

#define     A_pin 9                
#define     B_pin 2              
#define     C_pin 3
#define     D_pin 4
#define     E_pin 5
#define     F_pin 6
#define     Y_pin 7
#define     Z_pin 8

char    link[]= "";                // link data
String  readString = String(70);   // string for fetching data from address

boolean Ledstatus[8];

//var globale, pt afisarea etichetelor(cap de tabel)
char font_gray[] ="<font color=\"black\" size=\"5\">";
char font_green[]="<font color=\"green\" size=\"5\">";

prog_char string0[] PROGMEM = "<font color=\"gray\" size=\"2\"><input type='submit' name='A' value='1'>ON<br><input type='submit' name='A' value='0'>OFF</td>";
prog_char string1[] PROGMEM = "<font color=\"gray\" size=\"2\"><input type='submit' name='B' value='1'>ON<br><input type='submit' name='B' value='0'>OFF</td>";
prog_char string2[] PROGMEM = "<font color=\"gray\" size=\"2\"><input type='submit' name='C' value='1'>ON<br><input type='submit' name='C' value='0'>OFF</td>";
prog_char string3[] PROGMEM = "<font color=\"gray\" size=\"2\"><input type='submit' name='D' value='1'>ON<br><input type='submit' name='D' value='0'>OFF</td>";
prog_char string4[] PROGMEM = "<font color=\"gray\" size=\"2\"><input type='submit' name='E' value='1'>ON<br><input type='submit' name='E' value='0'>OFF</td>";
prog_char string5[] PROGMEM = "<font color=\"gray\" size=\"2\"><input type='submit' name='F' value='1'>ON<br><input type='submit' name='F' value='0'>OFF</td>";
prog_char string6[] PROGMEM = "<font color=\"gray\" size=\"2\"><input type='submit' name='Y' value='1'>ON<br><input type='submit' name='Y' value='0'>OFF</td>";
prog_char string7[] PROGMEM = "<font color=\"gray\" size=\"2\"><input type='submit' name='Z' value='1'>ON<br><input type='submit' name='Z' value='0'>OFF</td>";

PROGMEM const char *string_table[] =   // change "string_table" name to suit
{ string0,
 string1,
 string2,
 string3,
 string4,
 string5,
 string6,
 string7};
 
char buffer[140]; //lungimea max a unui string din PROGMEM +1


void setup()
{    
//  Serial.begin(57600); //enable serial datada print
 Ethernet.begin(mac, ip, gateway, subnet); //start Ethernet
 
 pinMode(A_pin, OUTPUT); //Set pin 4 to output
 pinMode(B_pin, OUTPUT);
 pinMode(C_pin, OUTPUT);
 pinMode(D_pin, OUTPUT);
 pinMode(E_pin, OUTPUT);
 pinMode(F_pin, OUTPUT);
 pinMode(Y_pin, OUTPUT);
 pinMode(Z_pin, OUTPUT);
 
 Serial.print("Started server");
 

}

void loop(){

 Client client = server.available();  // Create a client connection
   if (client) {
     while (client.connected()) {
       if (client.available()) {

         char c = client.read();

       if (readString.length() < 70) { //read char by char HTTP request
         readString.concat(c); } //store characters to string
         
       Serial.print(c); //output chars to serial port for debugging
       


       if (c == '\n') { //if HTTP request has ended
       
         
         //Serial.println("");
         int Ae = readString.indexOf("A=");
         int Be = readString.indexOf("B=");
         int Ce = readString.indexOf("C=");
         int De = readString.indexOf("D=");
         int Ee = readString.indexOf("E=");
         int Fe = readString.indexOf("F=");
         int Ye = readString.indexOf("Y=");
         int Ze = readString.indexOf("Z=");
         
         
                 
         //lets check if LED should be lighted
         if (readString.substring(Ae,(Ae+3)) == "A=1") { //led has to be turned ON
             digitalWrite(A_pin, HIGH); // set the LED on
             //Serial.println("A_pin paa");
             Ledstatus[0] = true;
         }
         if (readString.substring(Ae,(Ae+3))== "A=0") {  //led has to be turned OFF
           digitalWrite(A_pin, LOW); // set the LED OFF
           //Serial.println("A_pin av");
           Ledstatus[0] = false;
          }
         
         
         if (readString.substring(Be,(Be+3)) == "B=1") {
             digitalWrite(B_pin, HIGH);
             Ledstatus[1] = true;
         }
         if (readString.substring(Be,(Be+3)) == "B=0") {
           digitalWrite(B_pin, LOW);
           Ledstatus[1] = false;
          }
         
         
         if (readString.substring(Ce,(Ce+3)) == "C=0") {
           digitalWrite(C_pin, LOW);
           Ledstatus[2]=false;
         }
         if (readString.substring(Ce,(Ce+3)) == "C=1") {
           digitalWrite(C_pin, HIGH);
           Ledstatus[2]=true;
         }  
           
           
         if (readString.substring(De,(De+3)) == "D=0") {
           digitalWrite(D_pin, LOW);
           Ledstatus[3]=false;
         }
         if (readString.substring(De,(De+3)) == "D=1") {
           digitalWrite(D_pin, HIGH);
           Ledstatus[3]=true;
         }
         
         
         if (readString.substring(Ee,(Ee+3)) == "E=0") {
           digitalWrite(E_pin, LOW);
           Ledstatus[4]=false;
         }
         if (readString.substring(Ee,(Ee+3)) == "E=1") {
           digitalWrite(E_pin, HIGH);
           Ledstatus[4]=true;
         }
         
         
         if (readString.substring(Fe,(Fe+3)) == "F=0") {
           digitalWrite(F_pin, LOW);
           Ledstatus[5]=false;
         }
         if (readString.substring(Fe,(Fe+3)) == "F=1") {
           digitalWrite(F_pin, HIGH);
           Ledstatus[5]=true;
         }
         
         
         if (readString.substring(Ye,(Ye+3)) == "Y=0") {
           digitalWrite(Y_pin, LOW);
           Ledstatus[6]=false;
         }
         if (readString.substring(Ye,(Ye+3)) == "Y=1") {
           digitalWrite(Y_pin, HIGH);
           Ledstatus[6]=true;
         }
         
         
          if (readString.substring(Ze,(Ze+3)) == "Z=0") {
           digitalWrite(Z_pin, LOW);
           Ledstatus[7]=false;
         }
         if (readString.substring(Ze,(Ze+3)) == "Z=1") {
           digitalWrite(Z_pin, HIGH);
           Ledstatus[7]=true;
         }
         
client.println("HTTP/1.1 200 OK"); // now output HTML data starting with standart header
client.println("Content-Type: text/html");
client.println();
client.print  ("<body style=background-color:white>"); //set background to white

         // HTML Code
         client.println("<br />");
         client.println("<font color=\"blue\"><h2>WEB SERVER PRO</font></h2>");//send first heading
     
         //table
         client.println("<form><table border=2><tr>");
         for(int i=0; i<8; i++){
             client.println("<td>");
             if(Ledstatus[i]) client.println(font_green);
                   else       client.println(font_gray);
             client.println("<b>Led<h4>");
             client.println(i+1);
             client.println("</b></font><br />");
             
             strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i])));
             client.println(buffer);
             
             if(i==3) client.println("</tr><tr>"); //new row
           }
         client.println("</tr></table></form> <br />");
client.println("</body></html>");

client.stop();//stopping client
//Serial.println("Stopper klient");

//clearing string for next read
readString="";


}}}}}  
 
Please help me to understand why this errors apears :(

LAVco

Can you paste the html that gets outputted?

Alternatively you may want to take a look at Webduino by Ben Combee and Ran Talbott.
Common sense is not so common...

Resolved !  :)

Code: [Select]
client.println("</body></html>");
delay(500);
client.stop();//stopping client



"delay" was the problem pffffff

Go Up