#include "WiFi.h"
This library provides the function to connect the networks, and manage Wi-Fi settings.
- WiFi.begin(ssid, password): Connects the ESP32 to a Wi-Fi network.
- WiFi.scanNetworks(): Scans for available Wi-Fi networks.
- WiFi.status(): Returns the connection status (e.g., WL_CONNECTED).
- WiFi.localIP(): Returns the local IP address of the ESP32.
Encryption types: It refers to the method used by the Wi-Fi network to protect data sent between devices. Common types are:
- WIFI_AUTH_OPEN: No encryption (an open network).
- WIFI_AUTH_WEP: WEP encryption (outdated and insecure).
- WIFI_AUTH_WPA_PSK: WPA encryption with pre-shared key.
- WIFI_AUTH_WPA2_PSK: WPA2 encryption with pre-shared key (commonly used).
- WIFI_AUTH_WPA_WPA2_PSK: Mixed WPA/WPA2 mode.
#include "BluetoothSerial.h"
It helps in classic bluetooth communication.
- BluetoothSerial.begin(name): Starts Bluetooth with the specified name.
- BluetoothSerial.available(): Checks if data is available to read.
- BluetoothSerial.read(): Reads data from the Bluetooth connection.
- BluetoothSerial.write(data): Sends data over Bluetooth.
#include "ESP32Servo.h"
It controls servo motors with PWM signals.
- servo.attach(pin): Attaches a servo motor to a specified pin.
- servo.write(angle): Sets the servo to a specific angle (0–180 degrees).
- servo.detach(): Detaches the servo to stop the control signal.
#include "HTTPClient.h"
- http.begin(url): Starts an HTTP request to a specified URL.
- http.GET(): Sends an HTTP GET request.
- http.POST(data): Sends an HTTP POST request with data.
- http.end(): Ends the HTTP request.
It sends HTTP requests (GET, POST) to web servers.
#include "WebServer.h"
It runs a web server on ESP32 to serve web pages. Some common fucntions used are:
- server.on(path, handler): Handles a request for a specific URL path.
- server.begin(): Starts the web server.
- server.handleClient(): Handles incoming client requests.
#include "ESPAsyncWebServer.h"
It runs asynchronous web servers for handling multiple connections.
- server.on(path, HTTP_GET, handler): Handles asynchronous HTTP GET requests.
- server.serveStatic(path, fs, directory): Serves static files from a filesystem.
- server.begin(): Starts the asynchronous web server.
#include "Wire.h"
I2C communication for interfacing sensors and peripherals.
- Wire.begin(): Initializes I2C communication.
- Wire.requestFrom(address, quantity): Requests data from a device.
- Wire.write(data): Sends data to the I2C device.
- Wire.read(): Reads data received from the I2C device.
#include "SPI.h"
SPI communication for fast data exchange with peripherals.
- SPI.begin(): Initializes the SPI bus.
- SPI.transfer(data): Transfers data to SPI devices.
- SPI.end(): Terminates the SPI bus.
#include "Adafruit_Sensor.h"
Sensor library for interfacing with various Adafruit sensors.
- sensor.read(): Reads sensor data.
- sensor.begin(): Initializes the sensor.
References for pin configurations of esp32-cam link
References to program esp32-cam link
// Learn about the ESP32 WiFi simulation in
// https://docs.wokwi.com/guides/esp32-wifi
#include <WiFi.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h> //library for LCD
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);
#define NTP_SERVER "pool.ntp.org" //This is the address of the NTP server from which the device will request the current time. The "pool" is a set of publicly available NTP servers.
#define UTC_OFFSET 0
#define UTC_OFFSET_DST 0
void spinner() {
static int8_t counter = 0;
const char* glyphs = "\xa1\xa5\xdb";
LCD.setCursor(15, 1);
LCD.print(glyphs[counter++]);
if (counter == strlen(glyphs)) {
counter = 0;
}
}
void printLocalTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
LCD.setCursor(0, 1);
LCD.println("Connection Err");
return;
}
LCD.setCursor(8, 0);
LCD.println(&timeinfo, "%H:%M:%S");
LCD.setCursor(0, 1);
LCD.println(&timeinfo, "%d/%m/%Y %Z");
}
void setup() {
Serial.begin(115200);
LCD.init();
LCD.backlight();
LCD.setCursor(0, 0);
LCD.print("Connecting to ");
LCD.setCursor(0, 1);
LCD.print("WiFi ");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
spinner();
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
LCD.clear();
LCD.setCursor(0, 0);
LCD.println("Online");
LCD.setCursor(0, 1);
LCD.println("Updating time...");
configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);
}
void loop() {
printLocalTime();
delay(250);
}