I have the following test sketch that hangs on the Ethernet.begin(mac) statement. I implemented the patch described at dhcp request (ethernet.begin(mac)) hangs in parseDHCPResponse of Dhcp.cpp - Networking, Protocols, and Devices - Arduino Forum, but it did not fix the problem.
I've connected my PC to the Ethernet cable, so know that everything upstream from the cable is good. The cable goes to a switch, then a router, then a modem, then my ISP.
I would try to debug the Ethernet library code, but can't figure out how to do Serial.print from within a library.
Help would be much appreciated.
// BEFORE USING, in the code below,
// replace "your mac address here" with your device's mac address, and
// replace "www, xxx, y, zz" with a valid IP address for your device
//
#include <SPI.h>
#include <Ethernet.h>
// assign a MAC address for the ethernet controller.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
// fill in your address here:
byte mac[] = {
// "your mac address here"};
0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // unused MAC address assigned to controller
// fill in an available IP address on your network here,
// for manual configuration:
// my wifi router DHCP address pool is wwww.yyy.x.2 to wwww.yyy.x.254, so the following ip should be ok
//IPAddress ip(www, xxx, y, zz); // www, xxx, y, and zz must be replace by valid portions of an IP address
IPAddress ip(192, 168, 1, 1);
// initialize the library instance:
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
delay(3000); // delay so user can open serial monitor window
// start the Ethernet connection:
Serial.print("start EN: ");
int w = Ethernet.begin(mac);
Serial.print("done with BEGIN");
Serial.println(w);
if (w == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// DHCP failed, so use a fixed IP address:
Ethernet.begin(mac, ip);
}
else {
Serial.println("confgd via DHCP");
}
}
void loop() {
}