Ethernet

This is a library for Ethernet initialization. Initialization is necessary for both client and server. Connect with the Arduino shield and ioShield equipped with WIZnet's WIZ550io and control by SPI. Specify #include <SPI.h> and #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()
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

maintain

Description
Allows for the renewal of DHCP leases.
Syntax
Ethernet.maintain()
Parameters
None
Returns
0: Nothing happened
1: Renew failed
2: Renew success
3: Rebind fail
4: Rebind success

Example

Connect with DHCP, and then display the IP address.


#include <Arduino.h>
#include <SPI.h>
#include <Ethernet.h>
 
void setup()
{
    Serial.begin(9600);
     
    // start the Ethernet connection:
    if (Ethernet.begin() == 0) {
        Serial.println("Failed to configure Ethernet using DHCP");
        while(1);
    }
    // print your local IP address:
    Serial.println(Ethernet.localIP());
}
 
void loop() {
}