Ethernet

This is a library for Ethernet initialization. Specify #include <Ethernet.h> for use.

begin

Description
Initializes the Ethernet library and network settings. The DHCP automatically obtains an IP address, DNS, default gateway, and subnet mask.
Syntax
int Ethernet.begin(mac)
Ethernet.begin(mac, ip)
Ethernet.begin(mac, ip, dns)
Ethernet.begin(mac, ip, dns, gateway)
Ethernet.begin(mac, ip, dns, gateway, subnet)
Parameters
mac: MAC address (array of 6 bytes)
ip: IP address (array of 4 bytes)
dns: Name server address (array of 4 bytes)
gateway: Default gateway address (array of 4 bytes)
subnet: Subnet mask (array of 4 bytes)
Returns
If Ethernet.begin(mac) is successful = 1; if failure = 0. Others are none.

localIP

Description
Obtains the IP address of the board.
Syntax
IPAddress Ethernet.localIP()
Parameters
None
Returns
The IP address

Sample Program

Connect with DHCP, and then display the IP address.


#include <Arduino.h>
#include <Ethernet.h>
 
byte mac[] = {  
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
  
void setup()
{
    Serial.begin(9600);
    Serial.println("Start to connect..");
 
    // start the Ethernet connection:
    if (Ethernet.begin(mac) == 0) {
        Serial.println("Failed to configure Ethernet using DHCP");
        while(1);
    }
    // print your local IP address:
    Serial.println(Ethernet.localIP());
}
  
void loop() {
}