I am loading existing example in Arduino which runs as expected. What I don't understand is it sends serial data that I see on PC using Serial.Begin(9600) and Serial.println(); statements but Serial module is not defined anywhere? The same is true for WiFi module but at list there is an included for that #include <ESP8266WiFi.h>
My question is how this example is using these classes which are never defined?
Here is the complete example code.
#include <ESP8266WiFi.h>
const char ssid[] = "MyNetworkName";
const char pass[] = "password";
void setup() {
Serial.begin(9600);
while (!Serial) {
; // Wait for serial port to connect.
}
delay(1000);
Serial.println();
Serial.println("IoT DEVICE STARTED");
// Connect to Wi-Fi network
Serial.printf("\nConnecting to SSID %s ", ssid);
// Start the Wi-Fi connection and wait until it connects
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println(status);
Serial.print(".");
}
// Print the IP address
Serial.print("\nDevice is on the network at ");
Serial.print(WiFi.localIP());
}
void loop() {
// Nothing to do here yet
}
A global instance of the HardwareSerial (or equivalent depending on the board architecture) class is declared in the core library.
Here is an example from the Arduino AVR Boards core of the Uno, etc., but it's something similar for every board:
This is a relatively common approach in Arduino libraries where only a single instance is likely to be needed by the user. You can see another example of it in the Keyboard library:
skippy1:
The same is true for WiFi module but at list there is an included for that #include <ESP8266WiFi.h>