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() {}
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 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>.