Hardware Reference
In-Depth Information
The Finished Project
Figure 4-12
The completed networked air-quality meter.
DNS and DHCP
In Chapter 3 you learned that most Ethernet-connected devices obtain an IP address from their router using Dynamic Host
Control Protocol (DHCP), and that IP-connected devices learn the name of other servers and clients using the Domain Name
System (DNS). You can use DHCP and DNS with the Arduino Ethernet library as well. It's very simple—you just put the MAC
address in the Ethernet.begin() method, like so:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
Ethernet.begin(mac);
If the server grants an IP address, it returns true. If not, it returns false. The returned address is stored in Ethernet.localIP() .
You may want a few other variables to use DHCP as well, including Ethernet.subnetMask() , Ethernet.gatewayIP() , and Ethernet.
dnsServerIP() .
Using DNS is just as simple. Instead of passing a numeric server to the client.connect() command, give it a text string, like
so:
client.connect("www.example.com", 80);
The disadvantage of using DHCP and DNS is that they take a lot of RAM, so you may prefer to use the relevant numerical
addresses (once you know them).
Search WWH ::




Custom Search