I'm using something very similar to the WebServer example when using an Ethernet shield. I'm trying to add a countdown timer to my program so that when a "client" has connected to my Ethernet shield so I can effectively kick them off or shut things down when they have been connected for over 5 minutes. This will also allow my Arduino to power external items down when the "client" has left and I have no more people connected to my Ethernet shield.
Below is the WebServer example code. When I add a simple incremental loop (timer = timer + 1) to my program, it never gets beyond 1 or 2. I added this to the spot in the code when the client is available. I'm guessing the part of the code that is listening for incoming clients is causing my Arduino code to stop processing at that point while it is listening. Correct? In essence, I want to know how can I also add a countdown timer in the background?
void loop()
{
// listen for incoming clients
Client 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 (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(analogRead(analogChannel));
client.println("
");
}
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();
}
}