2016-09-24 19:53:46 +00:00
|
|
|
/*
|
|
|
|
* Connecting to a WiFi network with WPA
|
|
|
|
************************************************
|
|
|
|
* Originally adapted from https://www.arduino.cc/en/Tutorial/ConnectWithWPA
|
|
|
|
* by Starbeamrainbowlabs
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <WiFi.h>
|
|
|
|
|
|
|
|
char ssid[] = "evenstar-2.4";
|
2016-10-06 17:13:07 +00:00
|
|
|
char password[] = "yourPasswordHere";
|
2016-09-24 19:53:46 +00:00
|
|
|
// The current wifi status
|
|
|
|
int currentStatus = WL_IDLE_STATUS;
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
// put your setup code here, to run once:
|
|
|
|
Serial.begin(4800);
|
|
|
|
|
|
|
|
Serial.println("Hello, world!");
|
|
|
|
|
|
|
|
// Make sure that WiFi is supported
|
|
|
|
Serial.print("Testing for WiFi support - ");
|
|
|
|
if(WiFi.status() == WL_NO_SHIELD)
|
|
|
|
{
|
|
|
|
Serial.println("failed!");
|
|
|
|
Serial.println("WiFi shield not present :-(");
|
|
|
|
while(true) { delay(1000); }
|
|
|
|
}
|
|
|
|
Serial.println("success.");
|
|
|
|
|
|
|
|
Serial.println("Beginning connection sequence.");
|
|
|
|
while(currentStatus != WL_CONNECTED)
|
|
|
|
{
|
|
|
|
Serial.print("Attempting to connect to ");
|
|
|
|
Serial.print(ssid);
|
|
|
|
Serial.print(" - ");
|
|
|
|
|
|
|
|
currentStatus = WiFi.begin(ssid, password);
|
|
|
|
|
|
|
|
// Wait 10 seconds for the connection to start
|
|
|
|
delay(10000);
|
|
|
|
}
|
|
|
|
|
|
|
|
Serial.println("success!");
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
delay(1000);
|
|
|
|
printWiFiInfoLocal();
|
|
|
|
printWiFiInfoRemote();
|
|
|
|
delay(1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
void printWiFiInfoLocal()
|
|
|
|
{
|
|
|
|
Serial.print("IP Address: ");
|
|
|
|
Serial.println(WiFi.localIP());
|
|
|
|
|
|
|
|
Serial.print("MAC Address: ");
|
|
|
|
byte macAddress[6];
|
|
|
|
WiFi.macAddress(macAddress);
|
|
|
|
printMac(macAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
void printWiFiInfoRemote()
|
|
|
|
{
|
|
|
|
Serial.print("Current Wifi network:");
|
|
|
|
Serial.print(WiFi.SSID());
|
|
|
|
Serial.print(" (");
|
|
|
|
byte macAddress[6];
|
|
|
|
WiFi.macAddress(macAddress);
|
|
|
|
printMac(macAddress);
|
|
|
|
Serial.println(")");
|
|
|
|
}
|
|
|
|
|
|
|
|
void printMacPart(byte& macPart, bool end);
|
|
|
|
|
|
|
|
void printMac(byte macAddress[])
|
|
|
|
{
|
|
|
|
for(int i = 5; i >= 0; --i)
|
|
|
|
{
|
|
|
|
printMacPart(macAddress[i], i == 0 ? true : false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void printMacPart(byte& macPart, bool end)
|
|
|
|
{
|
|
|
|
Serial.print(macPart,HEX);
|
|
|
|
if(!end) Serial.print(":");
|
|
|
|
}
|
|
|
|
|