OTA basic modified esp8266

Hello,

I use esp8266 to make a OTA connection,
it gives me an error: 'server' is not captured

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <ESP8266WebServer.h>

//WIFI SETUP
const char* ssid = "Test net";
const char* password = "Abc112233Abc";

//VARIABLES
//OTA
bool Esp_update = false;
uint16_t time_elapsed = 0;
bool stopWorking = false;
int OTA_port = 8266;
const char* OTA_name = "LaserTag_1";
const char* OTA_pass = "LaserTagPass";



void setup() {
  Serial.begin(115200); 
  Serial.println("Booting");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  //CHECK WIFI STATUS
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    WiFi.begin(ssid, password);
  }

  //OTA SETINGS
  ArduinoOTA.setPort(OTA_port);
  ArduinoOTA.setHostname(OTA_name);
  ArduinoOTA.setPassword(OTA_pass);
  ESP8266WebServer server(80);

  ArduinoOTA.onStart([]() {
    Serial.println("OTA Start");
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("OTA End");
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("OTA Progress: %u%%\n", (progress / (total / 100)));
  });
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("OTA Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) Serial.println("OTA Auth Failed");
    else if (error == OTA_BEGIN_ERROR) Serial.println("OTA Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("OTA Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("OTA Receive Failed");
    else if (error == OTA_END_ERROR) Serial.println("OTA End Failed");
  });
  ArduinoOTA.begin();
  Serial.println("OTA Ready");
  Serial.print("Local IP address: ");
  Serial.println(WiFi.localIP());

  server.on("/update",[](){
      server.send(20, "text/plain", "...You have 45 seconds to update...");
      Esp_update = true;     
    });

  server.on("/restart",[](){
      server.send(20, "text/plain", "..............Restarting..............");
      delay(2000);
      ESP.restart();
    });

    server.on("/work",[](){
      server.send(20, "text/plain", "..............ESP stoped working..............");
      bool stopWorking = true;
    });

    server.begin();
}

void loop() {
  server.handleClient();
  if (Esp_update == true){
    while(time_elapsed < 45000){
      ArduinoOTA.handle();
      time_elapsed = millis();
      delay(10);
    }
    delay(1000);
    ESP.restart();
  }
  if (stopWorking == true){
    while (stopWorking == true){  
        delay(100);
      }
    } 
  
  

}

Thanks in advice

what should this do?

This code should make a virtual com port in the network so that the esp could be updated wierlessly!

a_kiselev_private:
This code should make a virtual com port in the network so that the esp could be updated wierlessly!

that is what the ArduinoOTA library does. what should the WebServer do?

The esp detects and displayes a web page with text so when someone visits the web page it should make a piece of code, a couple of months aggo i had tesame script and it all worked perfectly!