Hi experts,
I am trying to make a simple web server using Arduino duemilanove clone(ATmega328) & ENC28J60 ethernet module. I connected Ethernet module to my router's LAN port. (The internet connection to the router is from D-Link modem.)
I am using EtherCard library. On startup, arduino gives me IP address but when i try to view webpage by using this IP in browser, browser fails to load.
I think in my code setup() is executing but loop() is not executing as i tried a simple SerialTx function in loop & it didnt work...
Even MAC address get automatically changed to unknown format..!
My code is as follow. Please examine it & feel free to correct me..!
#include<EtherCard.h>
static byte myip[] PROGMEM = {118,110,55,69};
static byte mymac[] PROGMEM = {0x11,0xda,0x56,0xa6,0xc9,0x79};
static byte gateway[] PROGMEM = {10,0,0,1};
byte Ethernet::buffer[500];
void setup()
{
Serial.begin(9600);
Serial.println("\n[WebServer]");
if(ether.begin(sizeof Ethernet::buffer, mymac, 8)==0)
Serial.println("\nEthernet access failed");
else
Serial.println("\nEthernet Controller Initialized");
Serial.flush();
if (!ether.dhcpSetup())
Serial.println("Failed to get configuration from DHCP");
else
Serial.println("DHCP configuration done");
//ether.staticSetup(myip);
ether.printIp("IP Address:\t", ether.myip);
ether.printIp("Netmask:\t", ether.mymask);
ether.printIp("Gateway:\t", ether.gwip);
ether.printIp("MAC address:\t",ether.mymac);
Serial.println();
}
void loop()
{
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
SerialTx();
if(pos)
{
Serial.println("----------NEW PACKET------------");
Serial.println((char *)Ethernet::buffer + pos);
Serial.println("--------------------------------\n");
// create bfill as object
BufferFiller bfill = ether.tcpOffset();
bfill.emit_p(PSTR("HTTP/1.0 200 ok\r\n"
"Content-Type: text/html\r\nPragma: no-cache\r\n\r\n"
"<html><body><h1>Basic Web Server Using Arduino</h1></body></html>"));
ether.httpServerReply(bfill.position());
pos = 0;
}
}
void SerialTx()
{
Serial.println("Test if the arduino executes loop or not.!");
}
The Serial output is as follow: