I'm using the WiFi Rev 2 and have a program on a computer that sends it HTTP GET requests at about twice per second. I'm experiencing the following issue: each request appears to be processed twice. I attempt to prove it with the following image:
In that image, the first command (time: 637650988386069194) is processed at 171581. But, further down, it is processed again at 216215. I know that it is the same request because the tick time (637650988386069194), which comes from the sender, is the same on both. Here is the code:
void loop() {
AnalogWriteFrequency(8); // 1 (default) doesn't work, 4 almost works, 8/16/32/64 all work // log encoder position values readEncoders(false); // listen for incoming clients WiFiClient client = server.available(); String header; if (client) { Serial.println(""); Serial.print("new client: "); Serial.println(millis()); Serial.println("=========="); // an HTTP request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); Serial.write(c); header += 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) { //Serial.print("header: "); Serial.println(header); parseQueryStringAndPrintOutput(client, header); break; } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; //Serial.write("currentLineIsBlank = true"); } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; //Serial.write("currentLineIsBlank = false"); } } } // give the web browser time to receive the data //delay(1); // Clear the header variable header = ""; // close the connection: client.stop(); Serial.println("Client disconnected."); }
}
Each GET request header (the "header" variable in the code above) appears like this:
GET /?time=637650988386069194&username=&password=&motorleft=49&motorright=49 HTTP/1.1
Host: 192.168.1.81
Connection: Keep-Alive
Any idea why it would process each request twice?
(there is the other issue you may notice that the requests are out of order, but I think that is due to network latency and I haven't found a solution for that yet)