WifiServer and other errors for wireless LED setup

Hey guys,

I'm new to the Arduino world and I'm trying to replicate this project I found on YouTube. However, when I try to compile the code, I get the message "WifiServer does not name a type" and a multitude of other errors. The library that is needed to be downloaded is downloaded and included within the code. My guess is there's some additional things I need to change in the code to make it work but it's not exactly covered in the video. Thanks again for the help.

This is the video I'm trying to follow:

These are the errors:

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"

Test:7:1: error: 'WifiServer' does not name a type

WifiServer server(8181);

^

C:\Users\scott\OneDrive\Documents\Arduino\Test\Test.ino: In function 'void setup()':

Test:12:3: error: 'Wifi' was not declared in this scope

Wifi.begin(myssid, mypassword);

^

Test:12:14: error: 'myssid' was not declared in this scope

Wifi.begin(myssid, mypassword);

^

Test:12:22: error: 'mypassword' was not declared in this scope

Wifi.begin(myssid, mypassword);

^

C:\Users\scott\OneDrive\Documents\Arduino\Test\Test.ino: In function 'void loop()':

Test:28:3: error: 'WifiClient' was not declared in this scope

WifiClient client = server.available();

^

Test:28:14: error: expected ';' before 'client'

WifiClient client = server.available();

^

Test:30:10: error: 'client' was not declared in this scope

while (client.connected()) {

^

exit status 1
'WifiServer' does not name a type

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

This is the code I have:

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

WifiServer server(8181);

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

  Wifi.begin(myssid, mypassword);
  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";
  }
}

It's WiFi, not Wifi.

Did you type the whole sketch out yourself? You really need to take the time to learn how to copy and paste. It's an essential skill for any computer user, and especially for programmers:

Yup that was the problem. And yeah it's not a lot of code and I thought typing it out would help me understand it better. Now I'm running into a "timed out waiting for packet header" error but I'm gonna see if I can fix it first.

ZestfulScott:
I thought typing it out would help me understand it better.

I've heard that theory quite often. Many of the best programmers started by typing programs copied from computer magazines back in the olden days. Of course, they didn't have the option of copy/pasting the code back then. My thought on this is that you would learn more by doing a copy/paste, then studying the code and running experiments instead of spending that time typing the code and fixing all the bugs introduced during that process. But I'm no expert in these matters and everyone learns differently.

ZestfulScott:
Now I'm running into a "timed out waiting for packet header" error but I'm gonna see if I can fix it first.

I'm sorry to hear that. I've been dealing with a bit of the same today myself. I guess I managed to let the magic smoke out of a WeMos D1 Mini somehow.

I'm not very knowledgeable when it comes to troubleshooting upload problems on the ESP8266, but if you end up needing help I'm sure someone here on the forum will be able to provide assistance.