#include <ETH.h>
#include <WebServer.h> // Introduce corresponding libraries
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN
#define ETH_POWER_PIN 16
// Type of the Ethernet PHY (LAN8720 or TLK110)
#define ETH_TYPE ETH_PHY_LAN8720
// I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110)
#define ETH_ADDR 1
// Pin# of the I²C clock signal for the Ethernet PHY
#define ETH_MDC_PIN 23
// Pin# of the I²C IO signal for the Ethernet PHY
#define ETH_MDIO_PIN 18
WebServer server(80);
void setup() {
Serial.begin(115200);
Serial.println("Start Ethernet");
if (ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE))
{
//log_d("Ethernet is init!");
//IPAddress ip(192, 168, 0, 85);
//IPAddress gateway(192, 168, 0, 1);
//IPAddress mask(255, 255, 255, 0);
//ETH.config(ip, gateway, mask);
Serial.print("ETH MAC: ");
Serial.println(ETH.macAddress());
while (!((uint32_t)ETH.localIP())) {}; // Waiting for IP (leave this line group to get IP via DHCP)
String ip = ETH.localIP().toString();
if (ip != "0.0.0.0") {
Serial.println("OK");
Serial.print("IPv4: ");
Serial.println(ip);
}
}
server.on("/", HTTP_GET, []() {
server.send(200, "text/plain", "hello from esp32!");
});
server.onNotFound([]() {
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i = 0; i < server.args(); i++) {
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
});
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
}