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.
Arduino WiFi Shield
Shield-compatible Arduino board
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.
/*H******************************************************* This example connects to an unencrypted Wifi network. Then it prints the MAC address of the Wifi shield, the IP address obtained, and other network details. Circuit: * WiFi shield attached created 13 July 2010 by dlf (Metodo2 srl) modified 31 May 2012 by Tom Igoe ********************************************************/ #include <SPI.h> #include <WiFi.h> //************************* DEFINES ************************************ //************************* PROTOTYPES ************************************ void printWifiData(); void printCurrentNet(); //************************* VARIABLES ************************************ char ssid[] = "yourNetwork"; // THE NAME OF YOUR NETWORK int status = WL_IDLE_STATUS; // THE Wifi RADIO'S STATUS /*F******************************************************************** * **********************************************************************/ void setup() { //Initialize serial and wait for port to open: Serial.begin(9600); while( !Serial ) { ; } // WAIT FOR SERIAL PORT TO CONNECT. NEEDED FOR NATIVE USB PORT 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 } String fv = WiFi.firmwareVersion(); if( fv != "1.1.0") Serial.println("Please upgrade the firmware"); while( status != WL_CONNECTED) { Serial.print( "Attempting to connect to open SSID: "); Serial.println( ssid ); status = WiFi.begin( ssid ); delay( 10000 ); // WAIT 10 SECONDS FOR CONNECTION: } Serial.print("You're connected to the network"); printCurrentNet(); printWifiData(); // YOU'RE CONNECTED NOW, SO PRINT OUT THE DATA: } /*F******************************************************************** * **********************************************************************/ void loop() { // CHECK NETWORK CONNECTION ONCE EVERY 10 SECONDS delay( 10000 ); printCurrentNet(); } /*F******************************************************************** * **********************************************************************/ void printWifiData() { IPAddress ip = WiFi.localIP(); // PRINT YOUR wIfI SHIELD'S IP ADDRESS Serial.print( "IP Address: " ); Serial.println( ip ); Serial.println( ip ); byte mac[6]; WiFi.macAddress( mac ); Serial.print( "MAC address: "); Serial.print( mac[5], HEX); // PRINT YOUR MAC ADDRESS 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); IPAddress subnet = WiFi.subnetMask(); Serial.print( "NetMask: "); Serial.println( subnet ); // PRINT YOUR SUBNET MASK IPAddress gateway = WiFi.gatewayIP(); Serial.print( "Gateway: "); Serial.println( gateway ); // print your gateway address: } /*F******************************************************************** * **********************************************************************/ void printCurrentNet() { Serial.print( "SSID: "); // PRINT SSID OF NETWORK YOU'RE ATTACHED TO: Serial.println( WiFi.SSID() ); byte bssid[6]; WiFi.BSSID( bssid ); // PRINT MAC ADDRESS OF YOU'RE ROUTER Serial.print("BSSID: "); 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); long rssi = WiFi.RSSI(); Serial.print( "signal strength (RSSI):"); Serial.println( rssi ); // PRINT RECEIVED SIGNAL STRENGTH byte encryption = WiFi.encryptionType(); Serial.print( "Encryption Type:"); Serial.println( encryption, HEX); // PRINT ENCRYPTION TYPE: }
Last revision 2018/08/23 by SM