#include <SPI.h>
#include <Ethernet.h>
class MyServer : public EthernetServer {
public:
MyServer(uint16_t port) : EthernetServer(port) {
}
};
// MAC address for your Ethernet shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// IP address for your ESP32
IPAddress ip(192, 168, 8, 120);
// Subnet mask for your network
IPAddress subnet(255, 255, 255, 0);
// Gateway IP for your network
IPAddress gateway(192, 168, 8, 1);
// Ethernet Server on port 80 (http port)
void setup() {
// Initializing serial port for debugging purposes
Serial.begin(9600);
EthernetServer server(80);
while (!Serial) {
; // Wait for serial port to connect
}
// Initializing ethernet device
Ethernet.init(15); // Use Ethernet.init(pin) to configure the CS pin
Ethernet.begin(mac, ip, gateway, subnet);
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // Do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
// Start server
server.begin();
Serial.print("Server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// Listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("New client");