EtherShield (ENC28J60 ) control of an LED

Hi there,

I am trying to use an ENC28J60 to control an LED on the board. I have gone with the Ethershield library, but I’m flexible on this if the library isn’t powerful enough.

My code is based on one of the example scripts for Ethershield, and uses some code I found on the internet for an interactive button “onclick”.

In this library, it looks like the html data is stored in its own array “const char page PROGMEM =”. So I don’t know how to bridge the gap between things happening in the HTML section and things happening in the rest of the script.

Can anyone offer some advice? Most of the advice I have found relates to the official Arduino Ethernet shield/library, which looks significantly easier to work with.

here is my code.

Thanks :slight_smile:

// Present a "Will be back soon web page", as stand-in webserver.
// 2011-01-30 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
 
#include <EtherCard.h>

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

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

// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2E,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>"
    "Hello"
  "</title></head>"
  "<body>"
    "<h3>Web form</h3>"
    "<p><em>"
      "<button type=\"button\">Open </button>                                   "
      "<button type=\"button\">Close</button>
"
      "<button onclick=\"myFunction()\">Click me</button>"
      "<p id=\"demo\"></p>"
      "<script> function myFunction() {document.getElementById(\"demo\").innerHTML = \"Hello World\";}</script>"
    "</em></p>"
  "</body>"
"</html>"
;

void setup(){
  Serial.begin(57600);
  Serial.println("\n[backSoon]");
  
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 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);
  }
}

willsor:
Hi there,

I am trying to use an ENC28J60 to control an LED on the board. I have gone with the Ethershield library, but I'm flexible on this if the library isn't powerful enough.

My code is based on one of the example scripts for Ethershield, and uses some code I found on the internet for an interactive button "onclick".

In this library, it looks like the html data is stored in its own array "const char page PROGMEM =". So I don't know how to bridge the gap between things happening in the HTML section and things happening in the rest of the script.

Can anyone offer some advice? Most of the advice I have found relates to the official Arduino Ethernet shield/library, which looks significantly easier to work with.

Thanks :slight_smile:

You are going to have to learn that library. Or, find one that is more to your liking.

You might like this library UIPEthernet

Chuck.

Or, find one that is more to your liking.

Or spend a couple of bucks more and get a W5100 (+) based Ethernet shield.

Thanks for both of your replies.

I chose UIPEthernet in the end. Some web source said it was overly complex in comparison to EtherShield, however upon further investigation, it's a syntax-for-syntax replacement for the official Ethernet library, so it suited me well.