   }
 }
 
+void extractParams(String params)
+{
+  params[0] = ' ';
+  params.trim();
+  params.toUpperCase();
+  if (params.length() > 0)
+  {
+    params += "&";
+    if ((currentExecMode == TIMELAPSERUNNING) || (currentExecMode == REFRESH)) // Only refresh and stop allowed in timelapse mode
+    {
+      if (params.indexOf("REFRESH") >= 0) // Refresh webGUI
+        currentExecMode = REFRESH;
+      if (params.indexOf("STOP") >= 0) // STOP timelapse
+        currentExecMode = TIMELAPSESTOP;
+    }
+    else // blocked if timelapse running
+    {
+      if (params.indexOf("RESET") >= 0) // RESET form
+        currentExecMode = RESET;
+      else if (params.indexOf("SINGLE_SHOT") >= 0) // single shot
+        currentExecMode = ONESHOT;
+      else if ((params.indexOf("WAITFORGPIO") >= 0) && (startPin > -1)) // Wait for signal on input pin
+      {
+        currentExecMode = WAITFORGPIO;
+        setTimelapseParams(params);
+      }
+      else if ((params.indexOf("DELAYTOSTART") >= 0) && (currentNShots <= 0)) // Switch to timelapse
+      {
+        currentExecMode = TIMELAPSESTART;
+        setTimelapseParams(params);
+      }
+    }
+  }
+}
+
+void setTimelapseParams(String params) // Set timelapse parameters for modes WAITFORGPIO and START
+{
+  String par = params + " ";
+  int idx = par.indexOf("&"); // Find element delimiter
+  while (idx > 2)
+  {
+    String elem = par.substring(0, idx);
+    par = par.substring(idx + 1, par.length());
+    int idx2 = elem.indexOf("=");
+    if (idx2 > 1)
+    {
+      String elemName = elem.substring(0, idx2); // Variable name
+      String elemValue = elem.substring(idx2 + 1, elem.length()); // Variable value
+      if (elemName == "DELAYTOSTART")
+        delayToStart = elemValue.toInt();
+      if (elemName == "NUMBEROFSHOTS")
+        numberOfShots = elemValue.toInt();
+      if (elemName == "DELAYBETWEENSHOTS")
+        delayBetweenShots = elemValue.toInt();
+    }
+    idx = par.indexOf("&");
+  }
+}
+
 String generateHTMLPage(unsigned long sDelay, unsigned long nShots, unsigned long interval)
 {
   String refreshLine = "";
   String stateNotInTimelapse = "enabled";
   String buttonState = "disabled";
+  String waitForGPIOLine = "";
+  String waitForGPIOLineHint = "";
+  // disable webGUI elements while in timelapse
   if (((currentExecMode == TIMELAPSERUNNING) || (currentExecMode == REFRESH)) && (currentNShots > 0))
   {
     buttonState = "enabled";
     stateNotInTimelapse = "disabled";
   }
+  else if (currentExecMode == WAITFORGPIO)
+    currentAutorefresh = autorefresh;
   else
     currentAutorefresh = 0;
   if (currentAutorefresh > 0)
     refreshLine = "<meta http-equiv=\"refresh\" content=\"" + String(currentAutorefresh) + "; URL=http://" + myIPStr + "/\">";
+  if (startPin > -1) // webGUI elements für GPIO if defined
+  {
+    waitForGPIOLine = "<input type=submit value=\"Wait for GPIO" + String(startPin) + "\" " + stateNotInTimelapse + " name=WAITFORGPIO>";
+    waitForGPIOLineHint = "<FONT SIZE=-2>GPIO" + String(startPin) + " input LOW starts timelapse<BR>";
+  }
+  // HTML here
   String retVal = "<html><head><title>ANI Camera Remote</title>" + refreshLine + ""
-                  "<style>table, th, td { border: 0px solid black;} button, input[type=number], input[type=submit] "
-                  "{width:100px;height:24px;font-size:14pt;}</style></head><body>"
+                  "<style>table, th, td { border: 0px solid black;} button, input[type=number], input[type=submit]"
+                  "{width:120px;height:20px;font-size:12pt;}</style></head><body>"
                   "<font color=\"#000000\"><body bgcolor=\"#c0c0c0\">"
                   "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\">"
                   "<h2>" + prgTitle + " V" + prgVersion + "</h2>"
-                  "<table style=\"font-size:24px;\">"
+                  "<table style=\"font-size:16px;\">"
                   "<tr><td>Timelapse</td><td><a href=?function=RESET><button " + stateNotInTimelapse + ">Reset</button></a></td></tr>"
                   "<form method=GET>"
                   "<tr><td>Delay to start:</td><td><input " + stateNotInTimelapse + " id=delayToStart name=delayToStart type=number min=0 step=1 value=" + String(sDelay) + "> sec</td></tr>"

const int webServerPort = 80;                      // Port for web server

const int triggerPin = 2;                          // GPIO2 as trigger output

// Timelapse Defaults
const unsigned long default_delayToStart = 0;      // Delay in seconds till start of timelapse
const unsigned long default_numberOfShots = 10;    // Number of shots in timelapse mode
const unsigned long default_delayBetweenShots = 5; // Delay between shots in timelapse mode
const unsigned long default_autorefresh = 60;      // In timelapse mode autorefresh webGUI every 60 seconds, 0 = autorefresh off

// End of settings
//--------------------------------------------------

  20170720 Bugfix: Restarting timelapse after reconnect removed
  20170720 Information is displayed all the time, refresh button
  20170720 Autorefresh setting added
  20170722 Input pin as timelapse start
  --------------------------------------------------*/

#include <ESP8266WiFi.h>
