WiFi Reference
#include <WiFI.h>
begin disconnect config setDNS
SSID BSSID RSSI
macAddress encryption


WiFi - WiFi.
begin()
Description Initializes the WiFi library’s network settings and provides the current status. Syntax WiFi.begin(); WiFi.begin( ssid ); WiFi.begin( ssid, pass ); WiFi.begin( ssid, keyIndex, key ); Parameters ssid: the SSID (Service Set Identifier) is the name of the WiFi network you want to connect to. keyIndex: WEP encrypted networks can hold up to 4 different keys. This identifies which key you are going to use. key: a hexadecimal string used as a security code for WEP encrypted networks. pass: WPA encrypted networks use a password in the form of a string for security. Returns WL_CONNECTED when connected to a network WL_IDLE_STATUS when not connected to a network, but powered on Example /*F******************************************************************** * **********************************************************************/ #include char ssid[] = "yourNetwork"; // SSID OF NETWORK char pass[] = "secretPassword"; // PASSWORD OF WPA NETWORK /*F******************************************************************** * **********************************************************************/ void setup() { WiFi.begin( ssid, pass ); } /*F******************************************************************** * **********************************************************************/ void loop() {}
WiFi - WiFi.disconnect()
Description Disconnects the WiFi shield from the current network. Syntax WiFi.disconnect(); Parameters none Returns nothing
WiFi - 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 WiFi shield: /*F******************************************************************** * **********************************************************************/ #include #include IPAddress ip(192, 168, 0, 177); // IP ADDRESS FOR SHIELD char ssid[] = "yourNetwork"; // NETWORK SSID (NAME) char pass[] = "secretPassword"; // NETWORK PASSWORD (FOR WPA, OR AS KEY FOR WEP) int status = WL_IDLE_STATUS; /*F******************************************************************** * **********************************************************************/ void setup() { Serial.begin( BAUD ); // INITIALIZE SERIAL AND WAIT FOR PORT TO OPEN while( !Serial ) { ; // WAIT FOR SERIAL PORT TO CONNECT. NEEDED FOR lEONARDO ONLY } if( WiFi.status() == WL_NO_SHIELD) // CHECK FOR PRESENCE OF SHIELD { Serial.println( "WiFi shield not present"); while( true ); // DON'T CONTINUE } WiFi.config( ip ); while( status != WL_CONNECTED ) // ATTEMPT TO CONNECT TO Wifi NETWORK { 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 ); delay( 10000 ); // WAIT 10 SECONDS FOR CONNECTION } Serial.print( "IP Address: " ); // PRINT YOUR WiFi SHIELD'S IP ADDRESS Serial.println( WiFi.localIP() ); } /*F******************************************************************** * **********************************************************************/ void loop() {}

WiFi -
WiFi.SSID()
Description Gets the SSID of the current network Syntax WiFi.SSID(); WiFi.SSID( wifiAccessPoint ) Parameters wifiAccessPoint: specifies from which network to get the information Returns A string containing SSID WiFi shield is currently connected to. string containing name of network requested. Example: /*F******************************************************************** * **********************************************************************/ #include #include //SSID of your network char ssid[] = "yourNetwork"; int status = WL_IDLE_STATUS; // the Wifi radio's status /*F******************************************************************** * **********************************************************************/ void setup() { // INITIALIZE SERIAL Serial.begin( BAUD ); Serial.println( "Scanning available networks..." ); scanNetworks(); // SCAN FOR EXISTING NETWORKS Serial.println( "Attempting to connect to open network..."); status = WiFi.begin( ssid ); // ATTEMPT TO CONNECT USING WEP ENCRYPTION Serial.print( "SSID: " ); Serial.println( ssid ); } /*F******************************************************************** * **********************************************************************/ void loop() {} /*F******************************************************************** * **********************************************************************/ void scanNetworks() { // SCAN FOR NEARBY NETWORKS: Serial.println( "** Scan Networks **" ); byte numSsid = WiFi.scanNetworks(); Serial.print( "SSID List:" ); // PRINT LIST OF NETWORKS SEEN Serial.println( numSsid ); for( int thisNet = 0; thisNet
WiFi -
WiFi.BSSID()
Description Gets MAC address of the routher you are connected to Syntax WiFi.BSSID( bssid ); Parameters bssid : 6 byte array Returns A byte array containing the MAC address of the router the WiFi shield is currently connected to. Example /*F******************************************************************** * **********************************************************************/ #include // network SSID char ssid[] = "yourNetwork"; //password of your WPA Network char pass[] = "secretPassword"; /*F******************************************************************** * **********************************************************************/ void setup() { WiFi.begin( ssid, pass ); if( status != WL_CONNECTED ) { Serial.println( "Couldn't get a wifi connection"); while( true ); } // IF YOU ARE CONNECTED, PRINT OUT INFO ABOUT THE CONNECTION else { byte bssid[6]; // PRINT MAC ADDRESS OF ROUTER YOU'RE ATTACHED TO WiFi.BSSID( bssid ); Serial.print( "BSSID: "); Serial.print( bssid[5], HEX); Serial.print( ":" ); Serial.print( bssid[4], HEX); Serial.print( ":" ); Serial.print( bssid[3], HEX); Serial.print( ":" ); Serial.print( bssid[2], HEX); Serial.print( ":" ); Serial.print( bssid[1], HEX); Serial.print( ":" ); Serial.println( bssid[0], HEX); } } /*F******************************************************************** * **********************************************************************/ void loop() {}
WiFi - WiFi.

WiFi - WiFi.
encryptionType()
Description Gets the encryption type of the current network Syntax WiFi.encryptionType(); WiFi.encryptionType( wifiAccessPoint ); Parameters wifiAccessPoint: specifies which network to get information from Returns byte : value represents the type of encryption TKIP (WPA) = 2 WEP = 5 CCMP (WPA) = 4 NONE = 7 AUTO = 8 Example /*F******************************************************************** * **********************************************************************/ #include #include //SSID of your network char ssid[] = "yourNetwork"; //password of your WPA Network char pass[] = "secretPassword"; /*F******************************************************************** * **********************************************************************/ void setup() { WiFi.begin(ssid, pass); if( status != WL_CONNECTED ) { Serial.println( "Couldn't get a wifi connection"); while( true ); } else // IF CONNECTED, PRINT OUT INFO ABOUT CONNECTION { byte encryption = WiFi.encryptionType(); // PRINT ENCRYPTION TYPE Serial.print( "Encryption Type:" ); Serial.println( encryption, HEX ); } } /*F******************************************************************** * **********************************************************************/ void loop() {}
WiFi - WiFi.
scanNetworks()
Description Scans for available WiFi networks and returns the discovered number Syntax WiFi.scanNetworks(); Parameters none Returns byte : number of discovered networks Example /*F******************************************************************** * **********************************************************************/ #include #include char ssid[] = "yourNetwork"; // the name of your network /*F******************************************************************** * **********************************************************************/ void setup() { Serial.begin( BAUD ); int status = WiFi.begin( ssid ); if( status != WL_CONNECTED ) { Serial.println( "Couldn't get a WiFi connection"); while( true ); } else { // IF CONNECTED, SCAN FOR AVAILABLE WiFi NETWORKS AND PRINT NUMBER DISCOVERED Serial.println( "** Scan Networks **" ); byte numSsid = WiFi.scanNetworks(); Serial.print( "Number of available WiFi networks discovered:" ); Serial.println( numSsid ); } } /*F******************************************************************** * **********************************************************************/ void loop() {}
WiFi - WiFi.
status()
Description Return the connection status. Syntax WiFi.status(); Parameters none Returns WL_CONNECTED: assigned when connected to a WiFi network; WL_NO_SHIELD: assigned when no WiFi shield is present; WL_IDLE_STATUS: it is a temporary status assigned when WiFi.begin() is called and remains active until the number of attempts expires (resulting in WL_CONNECT_FAILED) or a connection is established (resulting in WL_CONNECTED); WL_NO_SSID_AVAIL: assigned when no SSID are available; WL_SCAN_COMPLETED: assigned when the scan network is completed; WL_CONNECT_FAILED: assigned when the connection fails for all the attempts; WL_CONNECTION_LOST: assigned when the connection is lost; WL_DISCONNECTED: assigned when disconnected from a network; Example /*F******************************************************************** * **********************************************************************/ #include #include char ssid[] = "yourNetwork"; // your network SSID (name) char key[] = "D0D0DEADF00DABBADEAFBEADED"; // your network key int keyIndex = 0; // your network key Index number int status = WL_IDLE_STATUS; // the Wifi radio's status /*F******************************************************************** * **********************************************************************/ void setup() { Serial.begin( 9600 ); // INIT SERIAL AND WAIT FOR PORT TO OPEN while( !Serial ) { ; // WAIT FOR SERIAL PORT TO CONNECT. nEEDED FOR lEONARDO ONLY } if( WiFi.status() == WL_NO_SHIELD ) // CHECK FOR PRESENCE OF SHIELD { Serial.println("WiFi shield not present"); while( true ); // DON'T CONTINUE } while( status != WL_CONNECTED ) // ATTEMPT TO CONNECT TO wIFI NETWORK { Serial.print( "Attempting to connect to WEP network, SSID: "); Serial.println( ssid ); status = WiFi.begin( ssid, keyIndex, key ); delay( 10000 ); // WAIT 10 SECONDS FOR CONNECTION } Serial.print( "You're connected to the network"); // ONCE ARE CONNECTED } /*F******************************************************************** * **********************************************************************/ void loop() { delay( 10000 ); // CHECK NETWORK STATUS CONNECTION ONCE EVERY 10 SECONDS Serial.println( WiFi.status() ); }
WiFi - WiFi.
getSocket()
Description gets the first socket available Syntax WiFi.getSocket(); Parameters none Returns int : first socket available
WiFi - WiFi.
macAddress()
Description Gets the MAC Address of your WiFi shield Syntax WiFi.macAddress( mac ); Parameters mac: a 6 byte array to hold the MAC address Returns byte array : 6 bytes representing the MAC address of your shield Example /*F******************************************************************** * **********************************************************************/ #include #include char ssid[] = "yourNetwork"; // the name of your network int status = WL_IDLE_STATUS; // the Wifi radio's status byte mac[6]; // the MAC address of your Wifi shield /*F******************************************************************** * **********************************************************************/ void setup() { Serial.begin( 9600 ); status = WiFi.begin( ssid ); Serial.println( "Couldn't get a wifi connection" ); while( true ); } else // IF CONNECTED, PRINT YOUR MAC ADDRESS: { WiFi.macAddress( mac ); Serial.print( "MAC: " ); Serial.print( mac[5], HEX); Serial.print( ":"); Serial.print( mac[4], HEX); Serial.print( ":"); Serial.print( mac[3], HEX); Serial.print( ":"); Serial.print( mac[2], HEX); Serial.print( ":"); Serial.print( mac[1], HEX); Serial.print( ":"); Serial.println( mac[0], HEX); } } /*F******************************************************************** * **********************************************************************/ void loop() {}