WiFiWebServer - slow to send responce (FIX).
Posted: Tue Sep 13, 2016 12:48 pm
Hi, all. Like most of you will have done I've done various projects based on the WiFiWebServer Example. One of the things that never quite worked for me was the fact that whilst the responce was sent, because the client wasn't closed the web page didn't update untill the program looped back to the start. Most reciently the was a right pain as I wanted to open and close some roller blinds with stepper motors. This takes 1 to 2 minuets to return to the start of the loop depending on the size of the blind, during that time as the web page doesn't update you are never quite sure if the request has been recieved. Anyway a simple fix.
The last part of WiFiWebServer Example is:
adding:
here:
causes the client to be disconnected and the web page is updated streight away.
This is not going to change the world but it may help someone.
Enjoy.
The last part of WiFiWebServer Example is:
Code: Select all
// Prepare the response
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
s += (val)?"high":"low";
s += "</html>\n";
// Send the response to the client
client.print(s);
delay(1);
Serial.println("Client disonnected");
// The client will actually be disconnected
// when the function returns and 'client' object is detroyed
}
adding:
Code: Select all
client.flush();
client.stop();
here:
Code: Select all
// Send the response to the client
client.print(s);
delay(1);
client.flush();
client.stop();
Serial.println("Client disonnected");
causes the client to be disconnected and the web page is updated streight away.
This is not going to change the world but it may help someone.
Enjoy.