title: Error while uploading to ESP8266 from Arduino IDE
body: <p>I was trying to upload code to my esp8266 from the Arduino IDE and it gives me this error:</p>
  
  <pre><code>   esptool.py v2.8
      Serial port COM6
      Connecting........_____....._____....._____....._____....._____....._____.....____Traceback (most recent call last):
        File "C:\Users\arcae_000\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/upload.py", line 65, in &lt;module&gt;
          esptool.main(cmdline)
        File "C:/Users/arcae_000/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/esptool\esptool.py", line 2890, in main
          esp.connect(args.before)
        File "C:/Users/arcae_000/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/esptool\esptool.py", line 483, in connect
          raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
      esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
      esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
  </code></pre>
  
  <p>I have the esp8266 board extension installed on the Arduino IDE and set to 'Generic ESP8266 Module'. I have tried changing the upload speed but it still fails. This is the code I used: </p>
  
  <pre><code>#include &lt;ESP8266WiFi.h&gt;
  
  const char* ssid = "SSID";//type your ssid
  const char* password = "PASSWORD";//type your password
  
  int ledPin = 2; // GPIO2 of ESP8266
  WiFiServer server(80);
  
  void setup() {
    Serial.begin(115200);
    delay(10);
  
  
    pinMode(ledPin, OUTPUT);
    digitalWrite(ledPin, LOW);
  
    // Connect to WiFi network
    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);
  
    WiFi.begin(ssid, password);
  
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
    Serial.println("");
    Serial.println("WiFi connected");
  
    // Start the server
    server.begin();
    Serial.println("Server started");
  
    // Print the IP address
    Serial.print("Use this URL to connect: ");
    Serial.print("http://");
    Serial.print(WiFi.localIP());
    Serial.println("/");
  
  }
  
  void loop() {
    // Check if a client has connected
    WiFiClient client = server.available();
    if (!client) {
      return;
    }
  
    // Wait until the client sends some data
    Serial.println("new client");
    while(!client.available()){
      delay(1);
    }
  
    // Read the first line of the request
    String request = client.readStringUntil('\r');
    Serial.println(request);
    client.flush();
  
    // Match the request
  
    int value = LOW;
    if (request.indexOf("/LED=ON") != -1) {
      digitalWrite(ledPin, HIGH);
      value = HIGH;
    } 
    if (request.indexOf("/LED=OFF") != -1){
      digitalWrite(ledPin, LOW);
      value = LOW;
    }
  
  // Set ledPin according to the request
  //digitalWrite(ledPin, value);
  
  
    // Return the response
    client.println("HTTP/1.1 200 OK");
    client.println("Content-Type: text/html");
    client.println(""); //  do not forget this one
    client.println("&lt;!DOCTYPE HTML&gt;");
    client.println("&lt;html&gt;");
  
    client.print("Led pin is now: ");
  
    if(value == HIGH) {
      client.print("On");  
    } else {
      client.print("Off");
    }
    client.println("&lt;br&gt;&lt;br&gt;");
    client.println("Click &lt;a href=\"/LED=ON\"&gt;here&lt;/a&gt; turn the LED on pin 2 ON&lt;br&gt;");
    client.println("Click &lt;a href=\"/LED=OFF\"&gt;here&lt;/a&gt; turn the LED on pin 2 OFF&lt;br&gt;");
    client.println("&lt;/html&gt;");
  
    delay(1);
    Serial.println("Client disonnected");
    Serial.println("");
  
  }
  </code></pre>
  
  <p><strong>(I have changed the SSID and Password values)</strong>
  I have searched every website I could find but I still couldn't fix it. The esp8266 is in flash mode. Also, I know that the esp8266 is not broken. I would appreciate any help.</p>