 #define POWER_LED D2
 
 // The port to listen for incoming TCP connections
-#define LISTEN_PORT 80
+ESP8266WebServer server(80);
 
 // How often to check for power off state
 unsigned long lastPowerCheck = millis();

  Serial.println(WiFi.localIP());
}

// Custom function accessible by the API
int flashLed(String command) {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
  return 1;
}

// Powers on the computer by pulling the power button low.
int powerOn(String command) {
  pinMode(POWER_BUTTON, OUTPUT);
  digitalWrite(POWER_BUTTON, LOW);
  delay(1000);
  digitalWrite(POWER_BUTTON, HIGH);
  pinMode(POWER_BUTTON, INPUT);
  return 1;
}

// Hard power off computer by holding power button 6 seconds.
int hardPowerOff(String command) {
  pinMode(POWER_BUTTON, OUTPUT);
  digitalWrite(POWER_BUTTON, LOW);
  delay(6000);
  digitalWrite(POWER_BUTTON,HIGH);
  pinMode(POWER_BUTTON, INPUT);
  return 1;
}

// Turn on relay, then press power.
// Parameter 0 = just do that.
// Parameter 1 = also wait until computer shuts down, then automatically flip relay off.
int powerOnGracefully(String command) {
  //Relay on
  digitalWrite(RELAY_PIN, HIGH);
  relayOn = 1;
  delay(5000);
  //Then power computer on as normal
  powerOn("");
  computerOn = 1;
  //Setup auto off if requested
  int autoOff = command.toInt();
  if (autoOff == 1) {
    relayOffWhenPowerDown = 1;
  } else {
    relayOffWhenPowerDown = 0;
  }
  return 1;
}


// Import required libraries
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
extern "C" {
  #include "user_interface.h"
}
