I want to connect and test the Arduino Mega to the PC via the ENC28J60 Ethernet module, but I need to do this without connecting to any router or network. That means the module's Ethernet port will be connected directly to the PC via an Ethernet cable. However, when I run the required code, I can't seem to open the IP address in the code in a browser. I would be very happy if someone knowledgeable could help. The code I used is attached:
#include <UIPEthernet.h> // ENC28J60 modülü için kütüphane
EthernetServer server(80); // HTTP sunucusu için port numarası
void setup() {
Serial.begin(9600);
uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC adresi
IPAddress ip(192, 168, 1, 177); // ENC28J60 modülünün IP adresi
Ethernet.begin(mac, ip); // Ethernet bağlantısını başlat
server.begin(); // Sunucuyu başlat
// Arduino'nun IP adresini seri monitöre yazdır
Serial.print("Sunucu IP adresi: ");
Serial.println(Ethernet.localIP());
}
void loop() {
EthernetClient client = server.available(); // Müşteri bağlantısını kontrol et
if (client) {
Serial.println("Yeni müşteri!");
// Müşteriden gelen isteği oku (bu örnekte, istek göz ardı edilir)
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// HTTP isteğinin sonunu bul
if (c == '\n' && currentLineIsBlank) {
// HTTP header'ı gönder
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
// Web sayfasını gönder
client.println("<!DOCTYPE html>");
client.println("<html>");
client.println("<head><title>ENC28J60 Test Sayfasi</title></head>");
client.println("<body><h1>Bu bir test sayfasidir</h1>");
client.println("<p>ENC28J60 Ethernet modülü üzerinden bağlantı başarılı.</p>");
client.println("</body></html>");
break;
}
if (c == '\n') {
// Yeni bir satır başlangıcı
currentLineIsBlank = true;
} else if (c != '\r') {
// Satırda karakter var
currentLineIsBlank = false;
}
}
}
// İstemci bağlantısını kapat
client.stop();
Serial.println("Müşteri bağlantısı kesildi.");
}
}