How do I retrieve the mac, ip, subnet, and gateway from the W5100 Ethernet shield? I can see you can get it from the W5100.h file but not sure how to go about getting that info back to my sketch. I am not trying to set them I wan't to ask the device what it has set
You can check the IP address of a running arduino/shield pair connected to a network by using programs such as ping or something like a port scanner running on a computer on the same network. The port scanner should give you an idea if the arduino/shield is responding. It can give you the IP address, Mac and an idea of the subnet, but I don't think it can determine the gateway on its own.
I understand what you are saying but what I would like is the device has a get and set you can retrieve it from the Ethernet shield I just don't know how if you look at the W5100.h file there is code for getting it.
its not the arduino thats losing the settings somehow the shield gets reset I don't do it but it would be simple to right a few lines to re initialize the shield if it did not have the same ip as was set...
Which shield are you using? The Adafruit version brings the Wiznet reset out to a pad. You have to connect a signal to it, or it'll be left open.
The directions recommend connecting it to the Arduino's reset. But, after reading some comments here, I connected it to a spare digital pin, and reset it in software. This allows my code to reset the Wiznet if I get an unrecoverable error on the Ethernet link.
I am using the NKC Ethernet Shield - http://www.nkcelectronics.com/nkc-ethernet-shield-for-arduino-mega--duemilanove--diecimila-diy-kit.html and I have the reset for the shield connected to a digital pin for control what I wanted to do is just ask the device periodically if it has the correct ip address and etc... vs just waiting for it time out for something its going to be a web host not a client so there is not an easy way to proactively reset the shield without sending data someplace...
A word of warning: the interface for reading/writing the address registers changed significantly from arduino-0017 (which is what I've been using) to 0021 (which I just downloaded). If you use those getXXXX() and setXXXX() routines, you'll definitely find that people using older versions of the IDE will have problems, and you may find that your code breaks when you download a new version.
Let's say you've defined the Ethernet parameters like this:
Then you could write a routine like this to verify that the parameters haven't been changed on you:
int check_Etherhealth(void)
uint8_t buf[6];
Ethernet.getGatewayIp(buf);
if (memcmp(buf, gateway, 4))
return 1;
Ethernet.getMACAddress(buf);
if (memcmp(buf, mac, 6))
return 2;
Ethernet.getIPAddress(buf);
if (memcmp(buf, ip, 4))
return 3;
return 0;
}
You could add other checks if you want: just make sure they return a non-zero on error. Using constants for the return values the way I did above is a poor practice: ideally, the different codes should be given symbolic names using #define or typedef enum, but I'm being lazy :