#include <>
/*H*******************************************************
This example prints the WiFi shield's MAC address, and
scans for available WiFi networks using the WiFi shield.
Every ten seconds, it scans again. It doesn't actually
connect to any network, so no encryption scheme is specified.
Circuit:
* WiFi shield attached
created 13 July 2010 by dlf (Metodo2 srl)
modified 21 Junn 2012 by Tom Igoe and Jaymes Dec
********************************************************/
#include <SPI.h>
#include <WiFi.h>
//************************* DEFINES ************************************
//************************* PROTOTYPES ************************************
void printMacAddress();
void printEncryptionType( int thisType );
void listNetworks();
//************************* VARIABLES ************************************
/*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
}
if( WiFi.status() == WL_NO_SHIELD ) // CHECK FOR THE PRESENCE OF SHIELD
{
Serial.println( "WiFi shield not present" );
// DON'T CONTINUE:
while( true );
}
String fv = WiFi.firmwareVersion();
if( fv != "1.1.0" )
Serial.println( "Please upgrade the firmware" );
printMacAddress(); // PRINT WiFi MAC ADDRESS:
}
/*F********************************************************************
*
**********************************************************************/
void
loop()
{
// SCAN FOR EXISTING NETWORKS:
Serial.println( "Scanning available networks..." );
listNetworks();
delay( 10000 );
}
/*F********************************************************************
*
**********************************************************************/
void
printMacAddress()
{
// 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 );
}
/*F********************************************************************
*
**********************************************************************/
void
listNetworks()
{
// SCAN FOR NEARBY NETWORKS:
Serial.println( "** Scan Networks **" );
int numSsid = WiFi.scanNetworks();
if( numSsid == -1 )
{
Serial.println( "Couldn't get a WiFi connection");
while( true );
}
// PRINT LIST OF NETWORKS SEEN:
Serial.print( "number of available networks:" );
Serial.println( numSsid );
// PRINT NETWORK NUMBER AND NAME FOR EACH NETWORK FOUND
for( int thisNet = 0; thisNet < numSsid; 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: " );
printEncryptionType( WiFi.encryptionType( thisNet ) );
}
}
/*F********************************************************************
*
**********************************************************************/
void
printEncryptionType( int thisType )
{
switch( thisType ) // READ ENCRYPTION TYPE AND PRINT OUT NAME
{
case ENC_TYPE_WEP:
Serial.println( "WEP" );
break;
case ENC_TYPE_TKIP:
Serial.println( "WPA" );
break;
case ENC_TYPE_CCMP:
Serial.println( "WPA2" );
break;
case ENC_TYPE_NONE:
Serial.println( "None" );
break;
case ENC_TYPE_AUTO:
Serial.println( "Auto" );
break;
}
}