Failed to connect to ESP8266: Timed out waiting for packet header

Hey guys,

So I'm trying to follow this video tutorial and I'm running into this error. I have both the ESP-12S (the one used in the video) and the ESP-32. I'm new to the Arduino world so maybe one works better than the other for my problem? Anyways, by doing some research, there might be some firmware that I have to flash onto the chip (tried following a tutorial for that and that didn't work either of course) so I'm out of ideas. If anyone can point me into the right direction that would be awesome. Thanks

Here's the video:

Here's the error:
Arduino: 1.8.11 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"

Executable segment sizes:

IROM : 242960 - code in flash (default or ICACHE_FLASH_ATTR)

IRAM : 27284 / 32768 - code in IRAM (ICACHE_RAM_ATTR, ISRs...)

DATA : 1256 ) - initialized variables (global, static) in RAM/HEAP

RODATA : 852 ) / 81920 - constants (global, static) in RAM/HEAP

BSS : 25024 ) - zeroed variables (global, static) in RAM/HEAP

Sketch uses 272352 bytes (26%) of program storage space. Maximum is 1044464 bytes.
Global variables use 27132 bytes (33%) of dynamic memory, leaving 54788 bytes for local variables. Maximum is 81920 bytes.
esptool.py v2.8
Serial port COM3
Connecting......................................____Traceback (most recent call last):
File "C:\Users\scott\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/upload.py", line 65, in
esptool.main(cmdline)
File "C:/Users/scott/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/scott/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

_

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Here's the code:

#include <ESP8266WiFi.h>
#define RELAY_PIN D1
const char* password = "password";
const char* ssid = "ssid";
const int port = 8181;

WiFiServer Server(8181);

void setup() {
  Serial.begin(9600);

  WiFi.begin("ssid, password");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println();
  Serial.print("Connected, IP Address");
  Serial.println(WiFi.localIP());

pinMode(RELAY_PIN, OUTPUT);
  
}

void loop() {

  WiFiClient client = Server.available();

  while (client.connected()) {
    if (client.available()) {

      uint8_t buf; //The data that is sent, just one byte
      size_t length = 1;
      client.read(&buf, length);
      client.write(handleCmd(buf));
      client.stop();
    }
  }

}

char *handleCmd(uint8_t cmd) {
  Serial.print(cmd);

  switch(cmd) {
    case 49:
    //49 is the ASCII value for 1, turn on lights
    digitalWrite(RELAY_PIN, HIGH);
    return "> Relay pin set to high \n";
    case 48:
    //48 is the ASCII value for 0, turn off lights
    digitalWrite(RELAY_PIN, LOW);
    return "> Relay pin set to low \n";

    default:
    return "> Send 1 for on, and 0 for off \n";
  }
}

bump

I recommend consulting a different project - one that has better documentation. Once you get the ESP working that way, you can go back and look at this one. There are hundreds, if not thousands, online.