Pages: [1] 2   Go Down
Author Topic: Web server, Reset button. Can someone check my code please!  (Read 810 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a webserver on my Arduino ethernet setup, it is currently displaying digital inputs and data stored in some variables perfectly. I have a variable called "floodcount" can anyone tell me how to make a button to go on the webpage that will allow me to reset the varialbe "floodcount" to 0.

Thanks in advance
« Last Edit: May 17, 2013, 09:33:25 am by Rich196 » Logged

Offline Offline
Sr. Member
****
Karma: 9
Posts: 254
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please post your code.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please post your code.

Please find it below!!

Code:
/* Water sensor
 
 This sketch will light up the LED on Pin 9, when water bridges the gap in the sensor pins 2-10
   
 

 */
//************************************************************************ Setting up ethernet port**************************************************
 #include <SPI.h>
#include <Ethernet.h>

// 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 };
IPAddress ip(192,168,99,99);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
 
 const int floodSensor1 = 2;     // the number of the Flood Sensor pin
 const int floodSensor2 = 3;     // the number of the Flood Sensor pin
 const int floodSensor3 = 4;     // the number of the Flood Sensor pin
 const int floodSensor4 = 5;     // the number of the Flood Sensor pin
 const int floodSensor5 = 6;     // the number of the Flood Sensor pin
 const int floodSensor6 = 7;     // the number of the Flood Sensor pin
 const int floodSensor7 = 8;     // the number of the Flood Sensor pin
// const int floodSensor8 = 11;     // the number of the Flood Sensor pin (using as pin 9 is test led output!!***********************************
 const int ledPin =  9;      // the number of the LED pin (pin 9 is the on board led) this will need to be changed to an output pin.*******************************

 // variables will change:
 int floodSensorState = 0;         // variable for reading the floodSensors status
 int floodcount = 0;               // variable for storing the total number of flood alerts
 int currentState = 0;             // variable for the counter
 int previousState = 0;            // variable for the counter

void setup() {
//*************************************************************Ehternet setup**********************************
 
   // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());

//*********************************************Working serial only**************************************************
     // initialize serial communication at 9600 bits per second:
//  Serial.begin(9600);

//********************************************************************************
   // initialize the LED pin as an output:
   pinMode(ledPin, OUTPUT);     
   // initialize the flood Sensor pin as an input:
   pinMode(floodSensor1, INPUT);
   pinMode(floodSensor2, INPUT);
   pinMode(floodSensor3, INPUT);
   pinMode(floodSensor4, INPUT);
   pinMode(floodSensor5, INPUT);
   pinMode(floodSensor6, INPUT);
   pinMode(floodSensor7, INPUT);
// pinMode(floodSensor8, INPUT);
 }
//........................................................... Reading input sensors in to variable************************************************
 void loop(){
   

   
 // Read each of the digital inputs, using the or function (||) if any of them are on it will make floodsensorstate variable high.
   
 if ( digitalRead(floodSensor1) || digitalRead(floodSensor2) || digitalRead(floodSensor3) || digitalRead(floodSensor4) || digitalRead(floodSensor5) || digitalRead(floodSensor6) || digitalRead(floodSensor7) )
{
   // make floodsensorstate variable high.   
   floodSensorState = HIGH;
   currentState = 1;
}
else
{
  // make floodsensorstate variable low.
   floodSensorState = LOW;
   currentState = 0;
}
//************************************************ Using variable to switch on output ****************************************************
  // check floodsensorstate variable if high turn led on.
 if (floodSensorState == HIGH) {     
     // turn LED on:   
     digitalWrite(ledPin, HIGH); 
   }
   else {
     // turn LED off:
     digitalWrite(ledPin, LOW);
   }   
//************************************************ counter ********************************************************************************

  if(currentState != previousState){     // current state not equal to previous state
  if(currentState == 1){                 // current state equal to 1
    floodcount = floodcount + 1;         // add one to counter
  }
}
  previousState = currentState;        // current state equal to previous state delay before re checking
delay(250);


//********************************************* Output of floodSensorState to serial *****************************************************
     // print out the state of the button:
  Serial.println(floodSensorState);
  Serial.println(floodcount);
  delay(1);        // delay in between reads for stability
 

 //*********************************************Ethernet code *******************************************************************************

  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
//********************************************************************************Web page tile***********************************         
          client.print("FIELD ELECTRONITCS LTD, WASTE WATER MANAGEMENT SYSTEM");
          client.println("<br />");
          client.println("<br />");
         
                    // add a meta refresh tag, so the browser pulls again every 2 seconds:
          client.println("<meta http-equiv=\"refresh\" content=\"2\">");
          // output the value of each analog input pin
         
          for (int analogChannel = 2; analogChannel < 9; analogChannel++) {    //Reads didgial inputs 2, 8. Each time is goes round the loop it read the next input.
            int sensorReading = digitalRead(analogChannel);
            client.print("Sensor input ");
            client.print(analogChannel - 1); // changes the text field so that input 2, its title sensor input 1!
            client.print(" is ");
            client.print(sensorReading);
            client.println("<br />");       
          }
 //****************************************************** Displaying The alarm status on the webpage ***************************************************
          client.println("<br />");    //*****************************
          client.print("Alarm Status ");      // Display the words " Alarm Status"
          client.print(floodSensorState);            // Display variable the words " Alarm Status"
          client.println("<br />");    //*************************
         
//****************************************************** Displaying The counter total on the webpage ***************************************************
          client.println("<br />");    //*****************************
          client.print("Alarm Counter ");      // Display the words " Alarm Counter"
          client.print(floodcount);            // Display variable the words " Alarm Counter"
          client.println("<br />");    //*************************
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }






//**********************************************************************************************************************************************

 
 }
 
 
Logged

Offline Offline
Sr. Member
****
Karma: 9
Posts: 254
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

At the moment you are skipping over the request from the client, you will need to parse this request to check for the button press and rest the counter accordingly.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
const int floodSensor1 = 2;     // the number of the Flood Sensor pin
 const int floodSensor2 = 3;     // the number of the Flood Sensor pin
 const int floodSensor3 = 4;     // the number of the Flood Sensor pin
 const int floodSensor4 = 5;     // the number of the Flood Sensor pin
 const int floodSensor5 = 6;     // the number of the Flood Sensor pin
 const int floodSensor6 = 7;     // the number of the Flood Sensor pin
 const int floodSensor7 = 8;     // the number of the Flood Sensor pin
An array would make a lot more sense, and use a lot less code.

Code:
   floodSensorState = HIGH;
The flood condition might be true. But, there is no (single) flood sensor, so it's state can't possibly be HIGH. A more meaningful name is in order.

Code:
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
Send a standard response, regardless of what the client asked for. Not a good plan.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for you help and suggestion. Sorry I am very new to this, could anyone perhaps do be an example code for this button. I am not very good with all the terminology, Especially with this web server stuff as I have never done it before.

Thanks

 
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am not very good with all the terminology, Especially with this web server stuff as I have never done it before.
Imagine that you work in a fast food restaurant.

A client comes in, and orders a chicken sandwich and onion rings. You cook a cheeseburger and french fries.
The next client wants a tuna sandwich and cole slaw. You cook a cheeseburger and french fries.

See a problem? The "You get it our way!" sign needs to be prominently displayed (right next to the going out of business sign).

Actually paying attention to what the client wants is a good thing.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Test code

Okay, So I have written some code that successfully zeros the variable "counter". See below:

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

// 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 };
IPAddress ip(192,168,99,99);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

int counter = 5; //*********************
int LEDpin = 9;
String readString = String(30);
String state = String(3);

void setup()


{
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  
  //Sets the LEDpin as an output
  pinMode(LEDpin,OUTPUT);
  
  digitalWrite(LEDpin,LOW);
  state = "OFF";
}

void loop()
{
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        
  
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply

        if (readString.length() < 30) {
          readString.concat(c);
        }
//************************************************************************************Action of button**************************************************************************
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          int counter1 = readString.indexOf("counter1=");

          if (readString.substring(counter1,counter1+10) == "counter1=T") {
            counter = 0;

          }
//**********************************************************************************Button to reset variable***************************************************************************************
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

            client.println("<a href=\"./?counter1=T\">reset<a>");
          
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }

//******************************************************* Print Variable on screen **********************************************************
       client.println("<br />");
       client.println("<br />");
       client.println(counter);
//*********************************************************************************************************************************************      
    // give the web browser time to receive the data
    delay(1);
    readString = "";
    // close the connection:
    client.stop();
  }



}



« Last Edit: May 17, 2013, 11:13:20 am by Rich196 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My main program works. I have also written a test program, for the web button to reset the variable, and it works fine. However when I put the code into the main program it will not work, but it has not broken anything in my main program either. I have put in all the test variables, into the main program.

The variable I am resetting is caller “counter” it is initialized to have a value of 5 on boot up and then the button should reset it to 0.

When I say it does not work. Everything displays on the web server as it should, however when you click the reset button the variable “counter” does not get set to 0.


Code:

 */
//******************************** Setting up ethernet port
 #include <SPI.h>
#include <Ethernet.h>

// 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 };
IPAddress ip(192,168,99,99);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
 
 const int floodSensor1 = 2;    
 const int floodSensor2 = 3;    
 const int floodSensor3 = 4;    
 const int floodSensor4 = 5;    
 const int floodSensor5 = 6;    
 const int floodSensor6 = 7;    
 const int floodSensor7 = 8;    

 const int ledPin =  9;

 // variables will change:
 int floodSensorState = 0;         // variable for reading the floodSensors status
 int floodcount = 0;               // variable for storing the total number of flood alerts
 int currentState = 0;             // variable for the counter
 int previousState = 0;            // variable for the counter
 
 
//************************************** Counter reset


int counter = 5; //
//int LEDpin = 9;
String readString = String(30);
String state = String(3);
 
 

void setup() {
//*************************************************************Ehternet setup
  
   // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());

//*********************************************Working serial only
     // initialize serial communication at 9600 bits per second:
//  Serial.begin(9600);

   // initialize the LED pin as an output:
   pinMode(ledPin, OUTPUT);      
   // initialize the flood Sensor pin as an input:
   pinMode(floodSensor1, INPUT);
   pinMode(floodSensor2, INPUT);
   pinMode(floodSensor3, INPUT);
   pinMode(floodSensor4, INPUT);
   pinMode(floodSensor5, INPUT);
   pinMode(floodSensor6, INPUT);
   pinMode(floodSensor7, INPUT);
// pinMode(floodSensor8, INPUT);
 }
//.........................Reading input sensors in to variable
 void loop(){
  

  
 // Read each of the digital inputs, using the or function (||) if any of them are on it will make floodsensorstate variable high.
  
 if ( digitalRead(floodSensor1) || digitalRead(floodSensor2) || digitalRead(floodSensor3) || digitalRead(floodSensor4) || digitalRead(floodSensor5) || digitalRead(floodSensor6) || digitalRead(floodSensor7) )
{
   // make floodsensorstate variable high.    
   floodSensorState = HIGH;
   currentState = 1;
}
else
{
  // make floodsensorstate variable low.
   floodSensorState = LOW;
   currentState = 0;
}
//***************************** Using variable to switch on output
  // check floodsensorstate variable if high turn led on.
 if (floodSensorState == HIGH) {    
     // turn LED on:    
     digitalWrite(ledPin, HIGH);  
   }
   else {
     // turn LED off:
     digitalWrite(ledPin, LOW);
   }  
//************************************************ counter

  if(currentState != previousState){     // current state not equal to previous state
  if(currentState == 1){                 // current state equal to 1
    floodcount = floodcount + 1;         // add one to counter
  }
}
  previousState = currentState;        // current state equal to previous state delay before re checking
delay(250);


//********************************************* Output of floodSensorState to serial
  // Print to serial port, the Flood alarm value after the text" Flood Alarm" to decribe what it it.

  String stringOne = "Flood Alarm: ";
  String stringThree = stringOne + floodSensorState;
  Serial.println(stringThree);
  
 // Print to serial port, the counter total value after the text" Counter total" to decribe what it it.

  String stringTwo = "Counter Total: ";
  String stringFour = stringTwo + floodcount;
  Serial.println(stringFour);
  
 //*********************************************Ethernet code

  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
//***********************************************Web page tile        
               client.println("<br />");
          client.println("<br />");
          
                    // add a meta refresh tag, so the browser pulls again every 2 seconds:
//          client.println("<meta http-equiv=\"refresh\" content=\"2\">");
          // output the value of each analog input pin
          
          for (int analogChannel = 2; analogChannel < 9; analogChannel++) {    //Reads didgial inputs 2, 8. Each time is goes round the loop it read the next input.
            int sensorReading = digitalRead(analogChannel);
            client.print("Sensor input ");
            client.print(analogChannel - 1); // changes the text field so that input 2, its title sensor input 1!
            client.print(" is ");
            client.print(sensorReading);
            client.println("<br />");      
          }
 //****************************************** Displaying The alarm status on the webpage
          client.println("<br />");           //*****************************
          client.print("Alarm Status ");      // Display the words " Alarm Status"
          client.print(floodSensorState);     // Display variable the words " Alarm Status"
          client.println("<br />");          
          
//****************************************************** Displaying The counter total on the webpage
        
          client.println("<br />");            
          client.print("Alarm Counter ");      // Display the words " Alarm Counter"
          client.print(floodcount);            // Display variable the words " Alarm Counter"
          client.println("<br />");            
          client.println("</html>");
//*********************************************************Counter reset code          
      
      
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply

        if (readString.length() < 30) {
          readString.concat(c);
        }
//*************************************************************Action of button
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          int counter1 = readString.indexOf("counter1=");

          if (readString.substring(counter1,counter1+10) == "counter1=T") {
            counter = 0;

          }
//****************************Button to reset variable
//          client.println("HTTP/1.1 200 OK");
//          client.println("Content-Type: text/html");
//          client.println();

            client.println("<a href=\"./?counter1=T\">reset<a>");
          

//************************ Print Variable on screen
       client.println("<br />");    
       client.println("<br />");    
       client.println(counter);    
    
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }

//*************************CLoses off the program and webpage
//          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
 
 }
 }
 

Thanks
« Last Edit: May 17, 2013, 10:55:15 am by Rich196 » Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3353
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it does not work any more

Sorry, that is not a proper way of describing a problem.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it does not work any more

Sorry, that is not a proper way of describing a problem.

My main program works. I have also written a test program, for the web button to reset the variable, and it works fine. However when I put the code into the main program it will not work, but it has not broken anything in my main program either. I have put in all the test variables, into the main program.

The variable I am resetting is caller “counter” it is initialized to have a value of 5 on boot up and then the button should reset it to 0.

When I say it does not work. Everything displays on the web server as it should, however when you click the reset button the variable “counter” does not get set to 0.
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3353
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Everything displays on the web server as it should, however when you click the reset button the variable “counter” does not get set to 0.

So the reset to 0 occurs in this part of the code:

Code:
if (readString.substring(counter1,counter1+10) == "counter1=T") {
  counter = 0;
}

If what you're describing is true, then this if statement isn't returning true. So, what is the value of the substring when its not true?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Everything displays on the web server as it should, however when you click the reset button the variable “counter” does not get set to 0.

So the reset to 0 occurs in this part of the code:

Code:
if (readString.substring(counter1,counter1+10) == "counter1=T") {
  counter = 0;
}

If what you're describing is true, then this if statement isn't returning true. So, what is the value of the substring when its not true?

That is correct. There is not other value, as I did not need it when I tested it the "test program" I wrote about.

All I want is a button to reset a variable called "counter" When the value stored in" counter" is greater than 0.

Thank you for your time!!
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3353
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That is correct. There is not other value, as I did not need it when I tested it the "test program" I wrote about.

All I want is a button to reset a variable called "counter" When the value stored in" counter" is greater than 0.

Thank you for your time!!

I asked a question that you didn't answer. I'll rephrase:

What is the value being returned by this statement:

Code:
readString.substring(counter1,counter1+10)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That is correct. There is not other value, as I did not need it when I tested it the "test program" I wrote about.

All I want is a button to reset a variable called "counter" When the value stored in" counter" is greater than 0.

Thank you for your time!!

I asked a question that you didn't answer. I'll rephrase:

What is the value being returned by this statement:

Code:
readString.substring(counter1,counter1+10)

I am sorry but I don't think I understand the question. I am really new to this. I found some example code an manipulated it to do what I wanted.

From what I think I understand. It is looking for the final character to be returned by the button. The tenth, hence the +10.

This is T, for true:

if (readString.substring(counter1,counter1+10) == "counter1=T").

This is the test code I wrote for making a button to zero a variable. This works perfectly in isolation here, but does not work when I put it into my main program. It no longer zeros the variable "counter":

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

// 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 };
IPAddress ip(192,168,99,99);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

int counter = 5; //*********************
int LEDpin = 9;
String readString = String(30);
String state = String(3);

void setup()


{
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
 
  //Sets the LEDpin as an output
  pinMode(LEDpin,OUTPUT);
 
  digitalWrite(LEDpin,LOW);
  state = "OFF";
}

void loop()
{
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
       
   
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply

        if (readString.length() < 30) {
          readString.concat(c);
        }
//************************************************************************************Action of button**************************************************************************
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          int counter1 = readString.indexOf("counter1=");

          if (readString.substring(counter1,counter1+10) == "counter1=T") {
            counter = 0;

          }
//**********************************************************************************Button to reset variable***************************************************************************************
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

            client.println("<a href=\"./?counter1=T\">reset<a>");
         
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }

//******************************************************* Print Variable on screen **********************************************************
       client.println("<br />");
       client.println("<br />");
       client.println(counter);
//*********************************************************************************************************************************************       
    // give the web browser time to receive the data
    delay(1);
    readString = "";
    // close the connection:
    client.stop();
  }

}
Logged

Pages: [1] 2   Go Up
Jump to: