#include <Servo.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

Servo servo;

// Replace with your network credentials
const char* ssid = "botnetcam";
const char* password = "12345678990";
 
ESP8266WebServer server(80);   //instantiate server at port 80 (http port)

String page = "";

void setup(void) {
  //the HTML of the web page
  page = "<center><a href=\"GO?alfa=0\"><button>0</button></a><a href=\"GO?alfa=5\"><button>5</button></a><a href=\"GO?alfa=15\"><button>15</button></a><a href=\"GO?alfa=45\"><button>45</button></a><a href=\"GO?alfa=90\"><button>90</button></a><a href=\"GO?alfa=180\"><button>180</button></a></center>";
  
  servo.attach(14); //D5 
  servo.write(0); //ставим вал под 0
  delay(1000); //ждем 2 секунды

  WiFi.begin(ssid, password); //begin WiFi connection
 
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
  
   
  server.on("/", [](){
    server.send(200, "text/html", page);
  });

  server.on("/GO", [](){

  // usage: http://ip/GO?alfa=10
  String sval = server.arg("alfa");
  int intalfa = sval.toInt();
  servo.write(intalfa); //ставим вал под угол intalfa переданный get запросом
  delay(1000); //ждем 2 секунды

  server.send(200, "text/html", page+"alfa: "+intalfa);
  
  });
 
   server.begin();
}

void loop(void){
server.handleClient();
}
