 #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();


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

//------------------------------------------------------------
//------------------------------------------------------------

// Variables to be exposed to the API
int relayOn =               0;
int computerOn =            0;
int relayOffWhenPowerDown = 0;

void setup() {
  Serial.begin(115200);
  initWifi();

  server.on("/", getStatus);
  server.on("/on", powerOn);
  server.on("/off", hardPowerOff);
  server.on("/relayon", powerOnGracefully);

  pinMode(LED_BUILTIN,  OUTPUT); //Built in LED for testing
  pinMode(POWER_BUTTON, INPUT);  //Connected to 'hot' wire of on button (switches between in and out)
  pinMode(POWER_LED,    INPUT);  //Connected to 'hot' wire of power LED (resistor?)

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

void loop() {
  //Handling of incoming requests
  server.handleClient();

  // Check for system power off state
  if (millis() > lastPowerCheck + POWER_CHECK_FREQUENCY) {
    if (relayOn && relayOffWhenPowerDown && !computerOn) {
      //It looks like we're shutdown, but lets make sure.
      delay(250);
      if (digitalRead(POWER_LED) == 0) {
        //OK then, power off Relay.
        delay(2000);
        digitalWrite(RELAY_PIN, LOW);
        relayOn = 0;
        relayOffWhenPowerDown = 0;
      }
    }
    lastPowerCheck = millis();
