Arduino Function: Ethernet.begin

Description

This function initializes the ethernet library and the network settings. With version 1.0, the library supports DHCP. Using Ethernet.begin(mac) with the proper network setup, the Ethernet shield will automatically obtain an IP address. This increases the sketch size significantly.

Syntax

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: the MAC (Media access control) address for the device. It is an array of 6 bytes. This is the Ethernet hardware address of your shield. Newer Arduino Ethernet Shields include a sticker with the device's MAC address. For older shields, choose your own. *ip: the IP address of the device. It is an array of 4 bytes. *dns: the IP address of the DNS server. It is an array of 4 bytes. Optional: defaults to the device IP address with the last octet set to 1 *gateway: the IP address of the network gateway It is an array of 4 bytes. Optional: defaults to the device IP address with the last octet set to 1. *subnet: the subnet mask of the network It is an array of 4 bytes. Optional: defaults to 255.255.255.0

Returns

 The DHCP version of this function, Ethernet.begin(mac), returns an int as follows: *1 on a successful DHCP connection *0 on failure. NOTE: Other versions don't have any returns.

Examples

#include 
#include  //if you are using Ethernet Shield 2, use instead 

// This is the media access control address for the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  
//the IP address for the shield
byte ip[] = { 10, 0, 0, 177 };    

void setup() {
  Ethernet.begin(mac, ip);
}

void loop () {}


Based on the reference originally written by Arduino Community,  wiring.org.co and  arduino.cc