Hardware Reference
In-Depth Information
The IP address is supplied in the form of an array of bytes:
// The IP address for this shield:
byte ip[] = { 192, 168, 0, 10 };
This IP address will be used on the local network. The DNS and gateway
parameters are optional; if omitted, they default to the same IP address with
the last octet set to one. The subnet parameter is also optional; if omitted, it
defaults to 255.255.255.0.
When the IP address has been obtained by DHCP, you can retrieve the IP
address from the Ethernet controller via localIP() .
Ethernet.localIP(); // Retrieve the IP address
If no parameters are specii ed, the IP address is returned as a string.
Serial.println(Ethernet.localIP());
It is, however, possible to obtain the IP address in byte format, by specifying
a byte to read.
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
DHCP leases are only available for a certain time; to maintain a DHCP lease,
you must specii cally request a renewal. On most servers, this will re-issue
the same IP address, but on some systems this might result in a change of IP
address. To renew a DHCP lease, call Ethernet.maintain() .
result = Ethernet.maintain();
maintain() returns a byte, depending on the DHCP answer. Table 9-1 lists
the values returned by this function.
Table 9-1: maintain() return codes
RESULT
DESCRIPTION
0
Nothing happened
1
Renew failed
2
Renew success
3
Rebind fail
4
Rebind success
Search WWH ::




Custom Search