• Arduino Uno
    • ENC28J60
    • EtherCard.h

i am trying to compile and run this example. But i am getting this error.

"exit status 1 'word homePage()' was declared 'extern' and later 'static' [-fpermissive]"

#include <EtherCard.h>

static byte mymac[] = {0x65,0x77,0x33,0x2D,0x30,0x66};
static byte myip[] = {192,168,0,99};

byte Ethernet::buffer[500];
BufferFiller bfill;

static word homePage() { 
  bfill = ether.tcpOffset();
  bfill.emit_p( PSTR ( 
    "HTTP/1.0 503 test page\r\n"
    "Content-Type: text/html\r\n"
    "Retry-After: 600\r\n"
    "\r\n"
    "<html>"
    "<head><title>"
    "Arduino test page"
    "</title></head>"
    "<body>"
    "<h3>Test</h3>" 
    "<p>Test</p>"
    "</body>"
    "</html>" 
  )) ;
  return bfill.position();
  }

void setup() {
  // put your setup code here, to run once:

  Serial.begin(57600);
  Serial.println("TEST");
  Serial.println();

  Serial.print("Status: ");
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) {
    Serial.println( "Failed to access Ethernet controller");
  }
  else {
    Serial.println( "Ethernet controller OK!"); 
    ether.staticSetup(myip); 
    ether.dhcpSetup();
  }
  Serial.println();

  ether.printIp("My IP: ", ether.myip);
  ether.printIp("GW IP: ", ether.gwip);
  ether.printIp("DNS IP: ", ether.dnsip);

}

void loop() {
  // put your main code here, to run repeatedly:
  word pos = ether.packetLoop(ether.packetReceive());
  if (pos){
    for (int i=pos;Ethernet::buffer[i]; i++) {
      Serial.print((char)Ethernet::buffer[i]);
      Serial.println();
      ether.httpServerReply(homePage());
    }
  }
}

Is something wrong with the code or library? The example was copied from the net. Library was updated.

Could u help me with this problem. How to fix it?

3

There are 3 best solutions below

0
On

Please check with the code I have provided. It is identical to the sketch provided by Jean-Claude Wipper's Github page except, I always have to supply Chip Select Pin to the "ether.begin" function or else my ENC28J60 won't respond.

// Present a "Will be back soon web page", as stand-in webserver.
// 2011-01-30 <[email protected]> http://opensource.org/licenses/mit-license.php
// Connection Diagram: https://i.stack.imgur.com/SvG7J.jpg

#include <EtherCard.h>

#define STATIC 1  // set to 1 to disable DHCP (adjust myip/gwip values below)
#define CS_PIN 10

#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,1,200 };
// gateway ip address
static byte gwip[] = { 192,168,1,1 };
#endif

// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[500]; // tcp/ip send and receive buffer

const char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
  "<head><title>"
    "Service Temporarily Unavailable"
  "</title></head>"
  "<body>"
    "<h3>This service is currently unavailable</h3>"
    "<p><em>"
      "The main server is currently off-line.<br />"
      "Please try again later."
    "</em></p>"
  "</body>"
"</html>"
;

void setup(){
  Serial.begin(9600);
  Serial.println("\n[backSoon]");

  if (ether.begin(sizeof Ethernet::buffer, mymac, CS_PIN) == 0) 
    Serial.println( "Failed to access Ethernet controller");
#if STATIC
  ether.staticSetup(myip, gwip);
#else
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");
#endif

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);  
  ether.printIp("DNS: ", ether.dnsip);  
}

void loop(){
  // wait for an incoming TCP packet, but ignore its contents
  if (ether.packetLoop(ether.packetReceive())) {
    memcpy_P(ether.tcpOffset(), page, sizeof page);
    ether.httpServerReply(sizeof page - 1);
  }
}

Download: Arduino EtherCard Library


Essential Task
Before uploading your sketch, you first need to connect your ENC28J60 module to your PC using LAN cable or you can also connect to your router. Now the main part comes. The variable "gwip" must match with your gateway IP address.

  • If you have connected with your PC, find your PC > Ethernet's IP address which may be look like "169.254.x.x":
    enter image description here

  • If you have connected to your router, place router's IP in "gwip".

Once you get Gateway IP, write it to "gwip" variable and upload your sketch :)

0
On

It seems that the function homePage was declared in the header without storafe class specifier static.

However then it is defined with the storage class specifier static

static word homePage() { 
//...

and the compiler reports about this inconsistence.

I think you may remove the storage class specifier static in the function definition.

Another approach is to place a function declaration with the storage class specifier static before the header. In this case the function will have internal linkage.

0
On

It likely that the changes in the tools used by the arduino gui are less tolerant than before and the library was updated.

It looks like your library is out of date, a search for homepage in the github repo only reveals 3 files, all of which are examples.

https://github.com/jcw/ethercard/search?utf8=%E2%9C%93&q=homepage

I suggest updating from https://github.com/jcw/ethercard.