I'm tweaking my network tester, as I noticed that if I don't have Ethernet plugged in, it never starts the program properly. I've attached an old copy of the file. Here's the section in question:
if (ethernetActive == 0)
{
// ethernet isnt active so lets get this show on the road
lcdPrint(0, 0, "Requesting IP", true);
if (Ethernet.begin(mac) != 0)
{
// ethernet is active now
ethernetActive = 1;
// waiting 1 second to let ethernet completely initialize
// ive seen this in other code so i put it here to be safe
delay(1000);
myLocalIp = Ethernet.localIP();
mySubnetMask = Ethernet.subnetMask();
// set connection timeout and retry count
// 0x07D0 == 2000
// 0x320 == 800
// 0x1F4 == 500
W5100.setRetransmissionTime(0x1F4);
W5100.setRetransmissionCount(1);
}
else
{
// ethernet failed to initialize, we will keep trying
lcdPrint(0, 1, "No DHCP");
}
}
else
{
// if everything seems good to go, display the main menu
mainMenu();
}
The thing is, it never gets to the else statement of "No DHCP". What I'd like to have it do is drop into the else statement where I can hard-code an APIPA address of 169.254.x.y to at least get it to run the menu and I could set an IP address manually.
You would have to handle the DHCP yourself. The Ethernet library contains the DhcpClass class, which is what does the DHCP work. The Ethernet.begin() calls that class, but just calls the generic version of it's beginWithDHCP() method. There is also a version which allows you to pass timeout values, so if you replicate what the Ethernet's .begin() is doing with regards to DHCP but use the timeout version instead, you should be able to attempt to get an IP address to then pass to the Ethernet library to use, or time out and pass your own IP address instead.
The thing is, it never gets to the else statement of "No DHCP".
Are you sure? It takes at least a minute to determine there is no dhcp server on the localnet. If you don't get that message, then there is no sense putting a static assignment if it will never run. You must determine why the "Ethernet.begin(mac);" (dhcp request call) is not timing out. It does for me.
The thing is, it never gets to the else statement of "No DHCP".
Are you sure? It takes at least a minute to determine there is no dhcp server on the localnet. If you don't get that message, then there is no sense putting a static assignment if it will never run. You must determine why the "Ethernet.begin(mac);" (dhcp request call) is not timing out. It does for me.
I don't know why it wouldn't time out after a minute. I've left this thing on for 15 minutes and it still just sits there. I've tried it with both Ethernet plugged in and unplugged.
edit: In my haste, I forgot the problem. Or does not show anything after "Starting w5100". It may take a minute or more to timeout and show "DHCP fail".