Sketch Will Only Compile With Copied Code (Not Typed Out)

Hi All - I’m using the Arduino IDE on the Huzzah ESP8266 breakout board. I have a successful program up and running. I’m now trying to refactor some of the code before moving on to my next step in the project.

However, I’m now getting error messages using the same code. Here’s the part I can’t understand. If I re-type the exact code, it fails to compile. But if I just copy and paste the code in, it compiles successfully. The code that I seem to be having the most trouble with is simply declaring an instance of WifiClient globally, so I created two new sketches to demonstrate just that. Again, if I write WifiClient client; it fails, but if I just copy that into my sketch, it compiles. See the two version below.

This version compiles successfully. I copied and pasted the code from an example.

#include <ESP8266WiFi.h>

const char* ssid = "myNetwork";
const char* pass = "myPassword";
const char* host = "data.sparkfun.com";
const int httpPort = 80;
  
WiFiClient client; //I copied this line from the ESP8266Wifi > WifiClient example. 

void setup() {
  Serial.begin(115200);
  delay(10); 
  WiFi.begin(ssid, pass);

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

  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  delay(5000);
  Serial.print("connecting to ");
  Serial.println(host);

  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
  } else {
    Serial.println("connection succeeded!");
  }
}

Now this version, I typed out exactly the same code from the example but won’t compile. This is the issue I’m having when refactoring my program.

#include <ESP8266WiFi.h>

const char* ssid = "myNetwork";
const char* pass = "myPassword";
const char* host = "data.sparkfun.com";
const int httpPort = 80;

WifiClient client; //I typed this code out. The WifiClient doesn't turn orange like the copied code. 

void setup() {
  Serial.begin(115200);
  delay(10);
  Wifi.begin(ssid,pass);

  while (Wifi.status() != WL_CONNECTED) {
    delay(5000);
    Serial.print(".");
  }
    Serial.println("");
    Serial.println("WiFi connected");  
    Serial.println("IP address: ");
    Serial.println(Wifi.localIP());
}

void loop() {
  delay(5000);
  Serial.print("connecting to ");
  Serial.println(host);

  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
  } else {
    Serial.println("connection succeeded!");
  }
}

And here are the errors:
WifiClient does not name a type
sketch_nov04b:9: error: ‘WifiClient’ does not name a type
WifiClient client;
^
In function ‘void setup()’:
sketch_nov04b:14: error: ‘Wifi’ was not declared in this scope
Wifi.begin(ssid,pass);
^
In function ‘void loop()’:
sketch_nov04b:31: error: ‘client’ was not declared in this scope
if (!client.connect(host, httpPort)) {
^
exit status 1
‘WifiClient’ does not name a type

Any ideas why my typed out code fails to compile but the copy and pasted code does? Any help is greatly appreciated!

C & C++ are case sensitive. WiFiClient is not the same as WifiClient.

WiFiClient client; //I copied this line from the ESP8266Wifi > WifiClient example.
WifiClient client; //I typed this code out. The WifiClient doesn't turn orange like the copied code.

Notice the difference in the WiFiClient to WifiClient. There is a case sensitivity in names.

G

stowite types faster than I can

Wow. So sorry for the oversight on my mistake! Thank you for pointing that out to me and not hitting me over the head with your response. I will make sure I double-quadruple check my code next time before posting.

You get an f. Or is it F. :slight_smile: