diff --git a/PositionGaugeServer.ino b/PositionGaugeServer.ino index 01c2a5026b324ae18b7cd7291f60fd329d70da44..56c03e90ee3abd5752a84904d145c02674f3e3ef 100644 --- a/PositionGaugeServer.ino +++ b/PositionGaugeServer.ino @@ -54,6 +54,7 @@ IPAddress subnet(255, 255, 0, 0); // ***** OTHER CONFIG *************************** const unsigned long update_interval = 1000; //[ms] const unsigned long SPC_timeout = 5; //[ms] 260 us per 4-bit word, 13 words, plus some buffer +const unsigned long WEB_timeout = 600; //[ms] Max time allowed waiting for web client // ***** GLOBAL VARIABLES *********************** @@ -261,7 +262,7 @@ void loop() { void readSPCinstrument(uint8_t ch) { - unsigned long SPC_timeout_time = millis(); + unsigned long SPC_timeout_time = millis()+SPC_timeout; digitalWrite(pinREQ[ch],HIGH); @@ -378,10 +379,13 @@ void readSPCinstrument(uint8_t ch) { void HTTPserver () { + unsigned long WEB_timeout_time = millis()+WEB_timeout; + EthernetClient client = srvWEB.available(); if(client) { Serial.println(); - Serial.println("New web client"); + Serial.print("New web client "); + Serial.println(client.remoteIP()); } else { return; @@ -393,7 +397,7 @@ void HTTPserver () { // We should also echo what the client sends boolean currentLineIsBlank = true; - while(client.connected()) { + while(client.connected() and millis() < WEB_timeout_time ) { if (client.available()) { //WARNING: If client does not "do it's thing", // the Arduino may become unresponsive. @@ -473,6 +477,12 @@ void HTTPserver () { } } + + if ( millis() >= WEB_timeout_time) { + Serial.println(); + Serial.println("WEB timed out."); + } + // give the web browser time to receive the data delay(10);//[ms] // close the connection: