ESP8266 Webserver push button momentary output and page refresh

Hi all, this should be a very simple fix. I am trying to have my webserver setup so that when I press the on button the led comes on and then turns off automatically after a delay. The issues is that the button press appends the LED=ON in the url and I can't seem to programatically delete it. The only way to remove it is with another button press. I need it deleted because I wan't the page to auto refresh every 5 seconds. This is because I also need to (eventually) read the status of an input pin and display that status on the webpage.

Ultimately this will become a wifi controlled gate opener. The gate system on my driveway just needs a pulse to open, so I can't have the output on all of the time, and I can't have it going on and off during a page refresh. My gate would just be constantly opening and then trying to close. My wife and kids would think it was demon possessed and then well that,s just not good..... As I mentioned the page refresh is necessary to show when the gate is closed.

My hardware is good and is all working.

Any help is greatly appreciated.

#include <ESP8266WiFi.h>

const char* ssid = "*********";
const char* password = "**********";

int ledPin = 4; // GPIO12 D6
WiFiServer server(80);

void setup() {
  Serial.begin(115200);
  delay(10);

  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");

}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  // Wait until the client sends some data
  Serial.println("new client");
  while (!client.available()) {
    delay(1);
  }

  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();



  // Set ledPin according to the request
  //digitalWrite(ledPin, value);
  int value = LOW;
  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println("Refresh: 5");
  client.println(""); // do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");

  client.println("

");
  client.println("<a href=\"/LED=ON\"><button>ON</button></a>");
  client.println("<a href=\"/LED=OFF\"><button>OFF</button></a></p>");
  client.println("</html>");

  // Match the request

  if (request.indexOf("/LED=ON") != -1) {
    digitalWrite(ledPin, HIGH);
    value = HIGH;
    delay(1500);
    digitalWrite(ledPin, LOW);
  }
  if (request.indexOf("/LED=OFF") != -1) {
    digitalWrite(ledPin, LOW);
    value = LOW;
  }

  client.print("Led pin is now: ");

  if (value == HIGH) {
    client.print("On");
  } else {
    client.print("Off");
  }

  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");

}

Maybe you need to do a redirect back to the original page? (ie from http://192.168.1.1/LED=ON to http://192.168.1.1)

see https://mediatemple.net/community/products/dv/204645160/how-do-i-redirect-my-site-using-a-meta-tag

have a look at my webserver for 32 IOs, there are buttons to set leds and they states are read back and set the red/green on/off icons as well it reads inputs!
http://forum.arduino.cc/index.php?topic=435455.0
feel free to use my code, you can download it, scroll down...

Turns our all I had to do was modify my Refresh code to add the URL I wanted to redirect to. Easy. Thanks to a good friend for pointing it out to me, and thanks to you guys who responded.

mega_hz, I never found your code, but your server is awesome.

  client.println("Refresh: 4;URL='//192.168.10.84:80/'>");