Arduino ESP8266 Webserver What I would like to do is control my garden lights using the ESP8266. For this I use the Arduino approach from here. This works great, I use bootstrap and jquery even :D all is well!

Switching lights on and off using my code is fine but now I'd like to switch some continues routines, like blinking. I can start the blinking from the webpage but this code is a loop so I cannot get back to turn it  off again.

I could make it blink for a set amount of loops, so eventually it will stop blinking and show the control webpage again.
Or I can add the blinking to the hardware, maybe use a 555 for the first time?
But there might be a better way of implementing this..

Using Google I found information about Break and Interrupts, not yet what I am looking for.

#include &lt;Arduino.h&gt;

#include &lt;ESP8266WiFi.h&gt;
#include &lt;WiFiClient.h&gt;
#include &lt;ESP8266WebServer.h&gt;
#include &lt;ESP8266mDNS.h&gt;

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

ESP8266WebServer server ( 80 );

const int led = 5;
String webPage = 
"&lt;!DOCTYPE html&gt;\
&lt;html lang='en'&gt;\
&lt;head&gt;\
  &lt;title&gt;Funny Bunny Control&lt;/title&gt;\
  &lt;meta charset='utf-8'&gt;\
  &lt;meta name='viewport' content='width=device-width, initial-scale=1'&gt;\
  &lt;link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'&gt;\
  &lt;script src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js'&gt;&lt;/script&gt;\
  &lt;script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'&gt;&lt;/script&gt;\
&lt;/head&gt;\
&lt;body&gt;\
&lt;div class='container-fluid'&gt;\
  &lt;div class='page-header'&gt;\
    &lt;h1&gt;Funny Bunny v0.1&lt;/h1&gt;\
  &lt;/div&gt;\
  &lt;p class='bg-info'&gt;Omdat snuffelen er bij hoort.&lt;/p&gt;\
  &lt;p class='bg-warning'&gt;Niet voeren aub.&lt;/p&gt;\
  &lt;div class='row'&gt;\
    &lt;div class='col-sm-4'&gt;&lt;a href='/aan' class='btn btn-info btn-block' role='button'&gt;aan&lt;/a&gt;&lt;/div&gt;\
    &lt;div class='col-sm-4'&gt;&lt;a href='/uit' class='btn btn-warning btn-block' role='button'&gt;uit&lt;/a&gt;&lt;/div&gt;\
  &lt;/div&gt;\
&lt;/div&gt;\
&lt;/body&gt;\
&lt;/html&gt;";

void handleRoot() {
  server.send(200, "text/html", webPage);
}

void aan() {
  digitalWrite ( led, 1 );
  server.send(200, "text/html", webPage);
}

void uit() {
  digitalWrite ( led, 0 );
  server.send(200, "text/html", webPage);
}

void setup ( void ) {
  pinMode ( led, OUTPUT );
  digitalWrite ( led, 0 );
  Serial.begin ( 115200 );
  WiFi.begin ( ssid, password );
  Serial.println ( "" );

  // Wait for connection
  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }

  Serial.println ( "" );
  Serial.print ( "Connected to " );
  Serial.println ( ssid );
  Serial.print ( "IP address: " );
  Serial.println ( WiFi.localIP() );

  if ( MDNS.begin ( "esp8266" ) ) {
    Serial.println ( "MDNS responder started" );
  }

  server.on ( "/", handleRoot );
  server.on ( "/aan", aan );
  server.on ( "/uit", uit );
  server.onNotFound ( handleRoot );
  server.begin();
  Serial.println ( "HTTP server started" );
}

void loop ( void ) {
  server.handleClient();
}
Take a look at the SimpleTimer [http://playground.arduino.cc/Code/SimpleTimer] library in the Arduino IDE environment.

You can have timers to:


call a function at a consistent interval,
call a function once after a set delay,
call a function a set number of times with a consistent interval
between.