Skip to content
Snippets Groups Projects
Commit 7484bb57 authored by Jonathan BAUDIN's avatar Jonathan BAUDIN
Browse files

Adding WiFi shield validation project

parent 84f536e5
No related branches found
No related tags found
No related merge requests found

Microsoft Visual Studio Solution File, Format Version 11.00
# Atmel Studio Solution File, Format Version 11.00
Project("{E66E83B9-2572-4076-B26E-6BE79FF3018A}") = "test", "test.cppproj", "{B3F859AD-E162-4C2F-9684-EAC6932FEC80}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Release|ARM = Release|ARM
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B3F859AD-E162-4C2F-9684-EAC6932FEC80}.Debug|ARM.ActiveCfg = Debug|ARM
{B3F859AD-E162-4C2F-9684-EAC6932FEC80}.Debug|ARM.Build.0 = Debug|ARM
{B3F859AD-E162-4C2F-9684-EAC6932FEC80}.Release|ARM.ActiveCfg = Release|ARM
{B3F859AD-E162-4C2F-9684-EAC6932FEC80}.Release|ARM.Build.0 = Release|ARM
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
This diff is collapsed.
/*
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 "Arduino.h"
#include <SPI.h>
#include <WiFi.h>
void printCurrentNet();
void printWifiData();
void httpRequest();
char ssid[] = "AVRGUEST"; // your network SSID (name)
char pass[] = "MicroController"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
WiFiClient client;
void setup() {
WiFi = WiFiClass();
client = WiFiClient();
// SPI.begin();
//Initialize Serial5 and wait for port to open:
Serial5.begin(9600);
while (!Serial5) {
; // wait for Serial5 port to connect. Needed for Leonardo only
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial5.println("WiFi shield not present");
// don't continue:
while(true);
}
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial5.print("Attempting to connect to WPA SSID: ");
Serial5.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
// you're connected now, so print out the data:
Serial5.print("You're connected to the network");
printCurrentNet();
printWifiData();
}
void loop() {
// check the network connection once every 10 seconds:
delay(10000);
printCurrentNet();
// Trying to connect to http://hasthelargehadroncolliderdestroyedtheworldyet.com/
Serial5.println("Trying to connect to : www.hasthelargehadroncolliderdestroyedtheworldyet.com :");
httpRequest();
while( client.available() )
{
Serial5.print((char)(client.read()));
}
Serial5.println("END");
}
void printWifiData() {
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial5.print("IP Address: ");
Serial5.println(ip);
Serial5.println(ip);
// print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
Serial5.print("MAC address: ");
Serial5.print(mac[5],HEX);
Serial5.print(":");
Serial5.print(mac[4],HEX);
Serial5.print(":");
Serial5.print(mac[3],HEX);
Serial5.print(":");
Serial5.print(mac[2],HEX);
Serial5.print(":");
Serial5.print(mac[1],HEX);
Serial5.print(":");
Serial5.println(mac[0],HEX);
}
void printCurrentNet() {
// print the SSID of the network you're attached to:
Serial5.print("SSID: ");
Serial5.println(WiFi.SSID());
// print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);
Serial5.print("BSSID: ");
Serial5.print(bssid[5],HEX);
Serial5.print(":");
Serial5.print(bssid[4],HEX);
Serial5.print(":");
Serial5.print(bssid[3],HEX);
Serial5.print(":");
Serial5.print(bssid[2],HEX);
Serial5.print(":");
Serial5.print(bssid[1],HEX);
Serial5.print(":");
Serial5.println(bssid[0],HEX);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial5.print("signal strength (RSSI):");
Serial5.println(rssi);
// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial5.print("Encryption Type:");
Serial5.println(encryption,HEX);
Serial5.println();
}
void httpRequest() {
// close any connection before send a new request.
// This will free the socket on the WiFi shield
client.stop();
// if there's a successful connection:
if (client.connect("www.hasthelargehadroncolliderdestroyedtheworldyet.com", 80)) {
Serial5.println("connecting...");
// send the HTTP PUT request:
client.println("GET / HTTP/1.1");
client.println("Host: www.hasthelargehadroncolliderdestroyedtheworldyet.com");
//client.println("User-Agent: ArduinoWiFi/1.1");
client.println("Connection: close");
client.println();
if( client.connected() )
{
Serial5.println("\tClient connected");
while( client.available() == 0 )
{
//Waiting for data
if( !client.connected() )
{
Serial5.println("\tClient disconnected !");
break;
}
}
}
else
{
Serial5.println("\tClient not connected");
}
}
else {
// if you couldn't make a connection:
Serial5.println("\tconnection failed");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment