-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ino
38 lines (30 loc) · 834 Bytes
/
server.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <WiFi.h>
#include <WebServer.h>
// Replace with your network credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
// Create an instance of the WebServer on port 80
WebServer server(80);
void setup() {
Serial.begin(115200);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println();
Serial.print("Connected to WiFi with IP: ");
Serial.println(WiFi.localIP());
// Define routes for the web server
server.on("/", HTTP_GET, []() {
server.send(200, "text/html", "<h1>ESP32 Web Server</h1><p>Hello from ESP32!</p>");
});
// Start the server
server.begin();
}
void loop() {
// Handle client requests
server.handleClient();
}