ENC28J60 Ethernet Module Problem.. Please Help..!


hi experts,

i trying make simple web server using arduino duemilanove clone(atmega328) & enc28j60 ethernet module. connected ethernet module router's lan port. (the internet connection router d-link modem.)
i using ethercard library. on startup, arduino gives me ip address when try view webpage using ip in browser, browser fails load.
i think in code setup() executing loop() not executing tried simple serialtx function in loop & didnt work...
even mac address automatically changed unknown format..!
my code follow. please examine & feel free correct me..!
code: [select]

#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 configuration 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 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 arduino executes loop or not.!");
}


the serial output follow:


could compare code against example:
https://github.com/jcw/ethercard/blob/master/examples/rbbb_server/rbbb_server.ino

and can check dhcp part example:
https://github.com/jcw/ethercard/blob/master/examples/testdhcp/testdhcp.ino

perhaps remove progmem mac , ip. don't know if possible progmem mac , ip ethercard library.

you can choose own mac address. enc28j60 has no build in mac address, set sketch.



Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > ENC28J60 Ethernet Module Problem.. Please Help..!


arduino

Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

How to format a Get Request

avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0x62