Code: Select all
// Ping a remote server, also uses DHCP and DNS.
// 2011-06-12 <jcw@equi4.com> http://opensource.org/licenses/mit-license.php
// $Id: pings.pde 7725 2011-06-13 14:07:56Z jcw $
#include <EtherCard.h>
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte myip[] = { 192,168,10,75 };
static byte gwip[] = {192,168,10,60 };
static byte dnsip[] = {192,168,10,10 };
byte Ethernet::buffer[700];
static uint32_t timer;
// called when a ping comes in (replies to it are automatic)
static void gotPinged (byte* ptr) {
ether.printIp(">>> ping from: ", ptr);
}
void setup () {
Serial.begin(57600);
Serial.println("\n[pings]");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
// if (!ether.dhcpSetup())
// Serial.println("DHCP failed");
if (!ether.staticSetup(myip, gwip, dnsip))
Serial.println("IP address setup failed");
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
#if 1
// use DNS to locate the IP address we want to ping
if (!ether.dnsLookup(PSTR("www.google.com")))
Serial.println("DNS failed");
#else
ether.parseIp(ether.hisip, "74.125.77.99");
#endif
ether.printIp("SRV: ", ether.hisip);
// call this to report others pinging us
ether.registerPingCallback(gotPinged);
timer = -9999999; // start timing out right away
Serial.println();
}
void loop () {
word len = ether.packetReceive(); // go receive new packets
word pos = ether.packetLoop(len); // respond to incoming pings
// report whenever a reply to our outgoing ping comes back
if (len > 0 && ether.packetLoopIcmpCheckReply(ether.hisip)) {
Serial.print(" ");
Serial.print((micros() - timer) * 0.001, 3);
Serial.println(" ms");
}
// ping a remote server once every few seconds
if (micros() - timer >= 5000000) {
ether.printIp("Pinging: ", ether.hisip);
timer = micros();
ether.clientIcmpRequest(ether.hisip);
}
}
My guess is that DHCP doesn't work. It didn't here

So I commented out the DHCP part and added static IP. Change the IP addresses (myip, gwip and dnsip) according to your local LAN!
After this small modification, I get this (open the Serial Monitor window):
Code: Select all
[pings]
IP: 192.168.10.75
GW: 192.168.10.60
DNS: 192.168.10.10
SRV: 74.125.79.104
Pinging: 74.125.79.104
24.728 ms
Pinging: 74.125.79.104
24.108 ms
Pinging: 74.125.79.104
24.232 ms
Pinging: 74.125.79.104
23.900 ms
Pinging: 74.125.79.104
24.732 ms
Pinging: 74.125.79.104
24.032 ms
Pinging: 74.125.79.104
24.492 ms
BTW, forget about the 2nd sketch you posted. That one is for the Arduino Ethernet shield, not for the JeeLabs EtherCard.
Using a sketch for Ethernet Shield with an EtherCard is like using a ATI driver for a nVidia card

If you need example, see File > Examples > Ethercard in the Arduino IDE, don't use the File > Examples > Ethernet examples.
Tip: I would report the issue at JeeLabs, this info can be useful for JCW.