- WiFi101
- Releases
- Usage
- Note
- Utilities
- Examples
- WiFi Class
- IPAddress class
- Getting Started with Arduino WiFi Shield 101
- Connecting the Shield
- Network Settings
- Scan for available networks
- Open network example
- WPA network example
- WEP Network example
- SPI
- Upgrading Firmware and uploading SSL certificates
- Tutorial
- Next steps
WiFi101
This library is compatible with all architectures so you should be able to use it on all the Arduino boards.
Releases
To use this library, open the Library Manager in the Arduino IDE and install it from there.
Usage
This library allows you to use the Arduino WiFi Shield 101 and the MKR1000 board. These are powerful IoT solutions with crypto-authentication, developed with ATMEL, that connects your Arduino or Genuino to the internet wirelessly. Connecting the board or the shield to a WiFi network is simple, no further configuration in addition to the SSID and the password are required. It can serve as either a server accepting incoming connections or a client making outgoing ones. The library supports WEP and WPA2 Personal encryption. Compared to the retired WiFi Shield and the related library, this product and library support all the same methods plus the connectSSL().
The board connected to the shield communicates with the WiFi shield 101 using the SPI bus. This is on digital pins 11, 12, and 13 on the Uno and pins 50, 51, and 52 on the Mega. On both boards, pin 10 is used as SS. On the Mega, the hardware SS pin, 53, is not used but it must be kept as an output or the SPI interface won’t work. Digital pin 7 is used as a handshake pin between the WiFi shield 101 and the underlying board, and should not be used. The WiFi101 library is very similar to the Ethernet and the library WiFi, and many of the function calls are the same.
For additional information on the Arduino WiFi Shield 101, see the Getting Started page and the Arduino WiFi Shield 101 hardware page. For more information on MKR1000 see the product page.
Note
This library requires that your board or shield has a matching firmware installed. When the library is updated, also the firmware might be updated, but it is not mandatory. To avoid any issue and ensure that you have the most up to date setup, we suggest that you check your WiFi101 library with the Arduino Software (IDE) Library Manager. There is an option in the Preferences that enables the check for updates of any of the installed libraries at startup. If you haven’t installed the WiFi101 library yet, you won’t get notified about its updates. Anyway, you get the library status just writing its name in the search field on top of the Library Manager.
When the library version installed on your computer is the latest available, you may check the firmware version of the board or the shield. We have prepared a utility sketch to check the firmware version and its matching with the library. If the firmware needs an update, another utility sketch enables the process. Below the link to the relevant tutorials.
Utilities
- CheckWiFi101FirmwareVersion : Reads the required firmware number required from library and matches with the one installed on the board or the shield.
- FirmwareUpdater : The sketch that must be loaded to allow the firmware and certificates update process through the integrated plugin of Arduino Software (IDE) rel. 1.6.10 or later.
Examples
- ConnectNoEncryption : Demonstrates how to connect to an open network
- ConnectWithWEP : Demonstrates how to connect to a network that is encrypted with WEP
- ConnectWithWPA : Demonstrates how to connect to a network that is encrypted with WPA2 Personal
- ScanNetworks : Displays all WiFi networks in range
- WiFiChatServer : Set up a simple chat server
- WiFiWebClient : Connect to a remote webserver
- WiFiWebClientRepeating : Make repeated HTTP calls to a webserver
- WiFiWebServer : Serve a webpage from the WiFi shield
- WiFiUdpSendReceiveString : Send and receive a UDP string
- UdpNTPClient : Query a Network Time Protocol (NTP) server using UDP
WiFi Class
- WiFi.begin()
- WiFi.beginProvision()
- WiFi.end()
- WiFi.beginAP()
- WiFi.disconnect()
- WiFi.config()
- WiFi.setDNS()
- WiFi.SSID()
- WiFi.BSSID()
- WiFi.RSSI()
- WiFi.encryptionType()
- WiFi.scanNetworks()
- WiFi.ping()
- WiFi.status()
- WiFi.macAddress()
- WiFi.lowPowerMode()
- WiFi.maxLowPowerMode()
- WiFi.noLowPowerMode()
- WiFi.APClientMacAddress()
- WiFi.getTime()
- WiFi.setPins()
IPAddress class
Getting Started with Arduino WiFi Shield 101
The Arduino WiFi 101 shield allows an Arduino board to connect to the internet using the WiFi101 library. The WiFi101 library can be downloaded using the Arduino Library Manager. The WiFI101 library is similar to the Ethernet library and many of the function calls are the same.
Connecting the Shield
To use the shield, mount it on top of an Arduino board (e.g. the Zero). To upload sketches to the board, connect it to your computer with a USB cable as you normally would. Once the sketch has been uploaded, you can disconnect the board from your computer and power it with an external power supply.
- Digital pin 7 is used as a handshake pin between the WiFi shield and the Arduino, and should not be used;
- Digital pin6 is attached to the on-board button;
- Digital pin5 drives the reset line of the on-board WINC1500 module;
Network Settings
The shield will connect to open networks, as well as those using WEP and WPA2 Personal encryption. The shield will not connect to networks using WPA2 Enterprise encryption.
The SSID (network name) must be broadcast for the shield to connect.
Depending on your wireless router configuration, you need different information.
- For an open (unencrypted) network, you need the SSID.
- For networks using WPA/WPA2 Personal encryption, you need the SSID and password.
- WEP network passwords are hexadecimal strings known as keys. A WEP network can have 4 different keys; each key is assigned a «Key Index» value. For WEP encrypted networks, you need the SSID, the key, and key number.
Scan for available networks
The sketch below is a good one to run the first time you use the board in a new area. This sketch will not connect to a network, but it will show you what networks the shield can view. Your WiFi shield will probably not see as many networks as a computer with a larger WiFi antenna. Once you have downloaded the sketch to your Arduino, open the serial port to see available networks.
#include #include void setup() // initialize serial and wait for the port to open: Serial.begin(9600); while(!Serial) ; // attempt to connect using WEP encryption: Serial.println("Initializing Wifi. "); printMacAddress(); // scan for existing networks: Serial.println("Scanning available networks. "); listNetworks(); > void loop() delay(10000); // scan for existing networks: Serial.println("Scanning available networks. "); listNetworks(); > void printMacAddress() // the MAC address of your Wifi shield byte mac[6]; // 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); > void listNetworks() // scan for nearby networks: Serial.println("** Scan Networks **"); byte numSsid = WiFi.scanNetworks(); // print the list of networks seen: Serial.print("number of available networks:"); Serial.println(numSsid); // print the network number and name for each network found: for (int thisNet = 0; thisNetnumSsid; thisNet++) Serial.print(thisNet); Serial.print(") "); Serial.print(WiFi.SSID(thisNet)); Serial.print("\tSignal: "); Serial.print(WiFi.RSSI(thisNet)); Serial.print(" dBm"); Serial.print("\tEncryption: "); Serial.println(WiFi.encryptionType(thisNet)); > >
Open network example
The sketch below shows you how to initiate a connection with an open network named «yourNetwork».
#include #include char ssid[] = "yourNetwork"; // the name of your network int status = WL_IDLE_STATUS; // the Wifi radio's status void setup() // initialize serial: Serial.begin(9600); // attempt to connect to an open network: Serial.println("Attempting to connect to open network. "); status = WiFi.begin(ssid); // if you're not connected, stop here: if ( status != WL_CONNECTED) Serial.println("Couldn't get a wifi connection"); while(true); > // if you are connected : else Serial.print("Connected to the network"); > > void loop() // do nothing >
WPA network example
The example below shows how to connect to a WPA/WPA2 Personal encrypted network named «yourNetwork» with a password «12345678».
#include #include char ssid[] = "yourNetwork"; // your network SSID (name) char pass[] = "12345678"; // your network password int status = WL_IDLE_STATUS; // the Wifi radio's status void setup() // initialize serial: Serial.begin(9600); // attempt to connect using WPA2 encryption: Serial.println("Attempting to connect to WPA network. "); status = WiFi.begin(ssid, pass); // if you're not connected, stop here: 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 Serial.println("Connected to network"); > > void loop() // do nothing >
WEP Network example
Your router will most likely have a settings dialog similar to the one below for generating the WEP key based on an ASCII passphrase:
If you do not have access to your router’s administrative tools, consult your network administrator.
Each key is 10 or 26 hexadecimal digits long (40 or 128 bits) and paired with a key number. For example, a 40-bit key, ABBADEAF01 will work, but ABBADEAF won’t work (too short) and ABBAISDEAF won’t work (I and S are not hexadecimal characters).vFor 128-bit, you need a string that is 26 characters long. D0D0DEADF00DABBADEAFBEADED will work because it’s 26 characters, all in the 0-9, A-F range.
NB : WEP provides a basic encryption mechanism, but it can be cracked. If you require strong encryption for your network, it is recommended you use WPA
The example below shows how to connect to a WEP encrypted network named «yourNetwork» with a hex key of «ABBADEAF01», and a key index of 0.
#include #include char ssid[] = "yourNetwork"; // your network SSID (name) char key[] = "ABBADEAF01"; // your network key int keyIndex = 0; //your network key Index number int status = WL_IDLE_STATUS; // the Wifi radio's status void setup() // initialize serial: Serial.begin(9600); // attempt to connect using WEP encryption: Serial.println("Attempting to connect to WEP network. "); status = WiFi.begin(ssid, keyIndex, key); // if you're not connected, stop here: 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 Serial.println("Connected to network"); > > void loop() // do nothing >
SPI
Arduino communicates with the shield using the SPI bus. This is on digital pins 11, 12, and 13 on the Uno and pins 50, 51, and 52 on the Mega. On both boards, pin 10 is used as SS. On the Mega, the hardware SS pin, 53, is not used, but it must be kept as an output or the SPI interface won’t work.
Upgrading Firmware and uploading SSL certificates
When it is needed, the WiFi101 library is updated to implement new features. This usually requires an update of the WiFi firmware with a specific tool. The shield comes with a number of root certificates that allow the secure connection with a wide variety of websites. If you need to use different certificates, you need to use the same tool. Please refer to the Firmware Updater sketch and plug-in documentation, available from the WiFi101 library page.
Tutorial
Here a list of tutorials that will help you in making very cool things!
Interact with Google Calendar This example shows you how to make requests to Google Calendar using a WiFi101 shield.
Weather audio notifier In this example, weather information from openweathermap.org is used to display the current weather information.
Upload data to Thingspeak Send a live stream of the light and temperature values in your environment using ThingSpeak.com.
Next steps
Refer to the WiFi 101 library page for more information on the functionality of the shield, as well as further examples.
The text of the Arduino getting started guide is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain.