Connect No Encryption
Demonstrates how to connect to an open network.
This example shows you how to connect to an open (not encrypted) 802.11b/g network with the Arduino WiFi shield. Your Arduino Software (IDE) serial monitor will provide information about the connection once it has connected.
Hardware Required
- Arduino WiFi Shield 
- Shield-compatible Arduino board 
Circuit
The WiFi shield uses pins 10, 11, 12, and 13 for the SPI connection to the HDG104 module. Digital pin 4 is used to control the chip select pin on the SD card.
You should have access to a 802.11b/g wireless network that connects to the internet for this example. You will need to change the network settings in the sketch to correspond to your particular networks SSID.
image developed using Fritzing. For more circuit examples, see the Fritzing project page
In the above image, the board would be stacked below the WiFi shield.
Code
1/*2
3 This example connects to an unencrypted Wifi network.4
5 Then it prints the  MAC address of the Wifi shield,6
7 the IP address obtained, and other network details.8
9 Circuit:10
11 * WiFi shield attached12
13 created 13 July 201014
15 by dlf (Metodo2 srl)16
17 modified 31 May 201218
19 by Tom Igoe20
21 */22#include <SPI.h>23#include <WiFi.h>24
25char ssid[] = "yourNetwork";     // the name of your network26int status = WL_IDLE_STATUS;     // the Wifi radio's status27
28void setup() {29
30  //Initialize serial and wait for port to open:31
32  Serial.begin(9600);33
34  while (!Serial) {35
36    ; // wait for serial port to connect. Needed for native USB port only37
38  }39
40  // check for the presence of the shield:41
42  if (WiFi.status() == WL_NO_SHIELD) {43
44    Serial.println("WiFi shield not present");45
46    // don't continue:47
48    while (true);49
50  }51
52  String fv = WiFi.firmwareVersion();53
54  if (fv != "1.1.0") {55
56    Serial.println("Please upgrade the firmware");57
58  }59
60  // attempt to connect to Wifi network:61
62  while (status != WL_CONNECTED) {63
64    Serial.print("Attempting to connect to open SSID: ");65
66    Serial.println(ssid);67
68    status = WiFi.begin(ssid);69
70    // wait 10 seconds for connection:71
72    delay(10000);73
74  }75
76  // you're connected now, so print out the data:77
78  Serial.print("You're connected to the network");79
80  printCurrentNet();81
82  printWifiData();83}84
85void loop() {86
87  // check the network connection once every 10 seconds:88
89  delay(10000);90
91  printCurrentNet();92}93
94void printWifiData() {95
96  // print your WiFi shield's IP address:97
98  IPAddress ip = WiFi.localIP();99
100  Serial.print("IP Address: ");101
102  Serial.println(ip);103
104  Serial.println(ip);105
106  // print your MAC address:107
108  byte mac[6];109
110  WiFi.macAddress(mac);111
112  Serial.print("MAC address: ");113
114  Serial.print(mac[5], HEX);115
116  Serial.print(":");117
118  Serial.print(mac[4], HEX);119
120  Serial.print(":");121
122  Serial.print(mac[3], HEX);123
124  Serial.print(":");125
126  Serial.print(mac[2], HEX);127
128  Serial.print(":");129
130  Serial.print(mac[1], HEX);131
132  Serial.print(":");133
134  Serial.println(mac[0], HEX);135
136  // print your subnet mask:137
138  IPAddress subnet = WiFi.subnetMask();139
140  Serial.print("NetMask: ");141
142  Serial.println(subnet);143
144  // print your gateway address:145
146  IPAddress gateway = WiFi.gatewayIP();147
148  Serial.print("Gateway: ");149
150  Serial.println(gateway);151}152
153void printCurrentNet() {154
155  // print the SSID of the network you're attached to:156
157  Serial.print("SSID: ");158
159  Serial.println(WiFi.SSID());160
161  // print the MAC address of the router you're attached to:162
163  byte bssid[6];164
165  WiFi.BSSID(bssid);166
167  Serial.print("BSSID: ");168
169  Serial.print(bssid[5], HEX);170
171  Serial.print(":");172
173  Serial.print(bssid[4], HEX);174
175  Serial.print(":");176
177  Serial.print(bssid[3], HEX);178
179  Serial.print(":");180
181  Serial.print(bssid[2], HEX);182
183  Serial.print(":");184
185  Serial.print(bssid[1], HEX);186
187  Serial.print(":");188
189  Serial.println(bssid[0], HEX);190
191  // print the received signal strength:192
193  long rssi = WiFi.RSSI();194
195  Serial.print("signal strength (RSSI):");196
197  Serial.println(rssi);198
199  // print the encryption type:200
201  byte encryption = WiFi.encryptionType();202
203  Serial.print("Encryption Type:");204
205  Serial.println(encryption, HEX);206}Last revision 2018/08/23 by SM
Suggest changes
The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.
License
The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.
