'Serial' does not name a type

Hi guys. I am new to programming. I have a Wemos D1, and using the Arduino IDE to program it.
I tried to hook up the board to WiFi, using the below sketch, but when I compile it I get the following error ;"'Serial' does not name a type".

The line highlighted is the following;
Serial.println(WiFi.localIP());

Can someone please point me in the right direction as to where I stuffed up?

#include <ESP8266WiFi.h>

void setup()
{
Serial.begin(115200);
Serial.println();
WiFi.begin("xxxxxxxxx", "xxxxxxxxx"); //enter your existing network name and password
}
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) //check if network is connected before continuing
{
delay(500);
Serial.print(".");
}
Serial.println(); //once connected print IP address received from DHCP server
Serial.print("Connected, IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {}

Hi Delta_G,

What I did was to accidentally replace ''#include <ESP8266WiFi.h>'' with #include "ESP8266WiFi.h'', and the code compiled. It loaded fine, and worked perfectly. I have no idea why that is, and am still trying to figure it out. Am very confused. As for the extra }, I see it, but it doesn't seem to affect the code?

The code you posted never compiled, irrespective of what #include was used.

I will take a video tonight when I get home, and post it here

JacoVenter:
I will take a video tonight when I get home, and post it here

What use is a video?
Just post code

The video will show you that the code does compile. I have no reason whatsoever to lie about it. But I will copy the code as it is now and post it.

#include "ESP8266WiFi.h"

void setup()
{
Serial.begin(115200);
Serial.println();

WiFi.begin("network-name", "pass-to-network");

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

Serial.print("Connected, IP address: ");
Serial.println(WiFi.localIP());
}

void loop() {}

The only reason it compiles now is because you removed the extra '}' from your code.

Changing the include didn't do anything, except slowing down the compilation by telling the preprocessor to look for the file in the local directory first instead of in the include path.
The correct version is #include <ESP8266WiFi.h>.

Pieter

Ahhhh, it seems I have less understanding of it than I thought. Thanks for the help though, much appreciated. And so we learn... :slight_smile: