Arduino

Reference Language | Libraries | Comparison | Changes

WiFi101

## WiFi.config()

#### Description

`WiFi.config()` allows you to configure a static IP address as well as change the DNS, gateway, and subnet addresses on the WiFi shield.

Unlike `WiFi.begin()` which automatically configures the WiFi shield to use DHCP, `WiFi.config()` allows you to manually set the network address of the shield.

Calling `WiFi.config()` before `WiFi.begin()` forces `begin()` to configure the WiFi shield with the network addresses specified in `config()`.

You can call `WiFi.config()` after `WiFi.begin()`, but the shield will initialize with `begin()` in the default DHCP mode. Once the `config()` method is called, it will change the network address as requested.

#### Syntax

WiFi.config(ip);
WiFi.config(ip, dns);
WiFi.config(ip, dns, gateway);
WiFi.config(ip, dns, gateway, subnet);

#### Parameters

ip: the IP address of the device (array of 4 bytes)

dns: the address for a DNS server.

gateway: the IP address of the network gateway (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 (array of 4 bytes). optional: defaults to 255.255.255.0

#### Returns

Nothing

#### Example

This example shows how to set the static IP address, 192.168.0.177, of the LAN network to the Arduino WiFi Shield 101:

#include <SPI.h>
#include <WiFi101.h>
// the IP address for the shield:
IPAddress ip(192, 168, 0, 177);
char ssid[] = "yourNetwork"; // your network SSID (name)
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;
void setup()
{
// Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
while(true); // don't continue
}
WiFi.config(ip);
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
// print your WiFi shield's IP address:
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
}
void loop () {}
[Get Code]
Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.

### Share

### This link has expired.
Please re-subscribe to our Newsletters.

### Subscribe to our Newsletters

Email

Please enter a valid email to subscribe

Arduino Newsletter
Arduino Store Newsletter

### Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy

###### Newsletter

- ©2015 Arduino
- Copyright Notice
- Contact us
- About us
- Careers