diff --git a/WiFi/examples/ScanNetworksOpen/ScanNetworksOpen.ino b/WiFi/examples/ScanNetworksOpen/ScanNetworksOpen.ino new file mode 100644 index 000000000..3e5f07534 --- /dev/null +++ b/WiFi/examples/ScanNetworksOpen/ScanNetworksOpen.ino @@ -0,0 +1,137 @@ +/* + + Open connection using the WiFi shield. Attempts to connect + and prints out info about the network + + Circuit: + * WiFi shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 15 Sep 2011 + by Tom Igoe + */ + + +#include +#include + +char ssid[] = "yourNetwork"; // the name of your network +int status = WL_IDLE_STATUS; // the Wifi radio's status + +byte mac[6]; // the MAC address of your Wifi shield +IPAddress ip; // the IP address of your shield +IPAddress gateway; // the router's address +IPAddress subnet; // the subnet mask + +void setup() { + // initialize serial: + Serial.begin(9600); + + // scan for existing networks: + Serial.println("Scanning available networks..."); + scanNetworks(); + + // attempt to connect using WEP encryption: + Serial.println("Attempting to connect to open network..."); + status = WiFi.begin(ssid); + + Serial.print("SSID: "); + Serial.println(ssid); + + // if you're not connected, stop here: + if ( status != WL_CONNECTED) { + Serial.println("Couldn't get a wifi connection"); + while(true); + } + // if you are connected, print out info about the connection: + else { + printIpData(); + printCurrentNet(); + } +} + +void loop() { + // do nothing +} + +void printIpData() { + // print your WiFi shield's IP address: + ip = WiFi.localIP(); + Serial.println(ip); + + + // print your subnet mask: + subnet = WiFi.subnetMask(); + Serial.print("NETMASK: "); + Serial.println(subnet); + + + // print your gateway address: + gateway = WiFi.gatewayIP(); + Serial.print("GATEWAY: "); + Serial.println(gateway); + + // 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); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + Serial.print(bssid[5],HEX); + Serial.print(":"); + 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); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("RSSI:"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption,HEX); +} + +void scanNetworks() { + // scan for nearby networks: + Serial.println("** Scan Networks **"); + byte numSsid = WiFi.scanNetworks(); + + // print the list of networks seen: + Serial.print("SSID List:"); + Serial.println(numSsid); + // print the network number and name for each network found: + for (int thisNet = 0; thisNet +#include + +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password +int status = WL_IDLE_STATUS; // the Wifi radio's status + +byte mac[6]; // the MAC address of your Wifi shield +IPAddress ip; // the IP address of your shield +IPAddress gateway; // the router's address +IPAddress subnet; // the subnet mask + +void setup() { + // initialize serial: + Serial.begin(9600); + // scan for existing networks: + Serial.println("Scanning available networks..."); + //WiFi.begin(); + scanNetworks(); + + // attempt to connect using WEP encryption: +// Serial.println("Attempting to connect to WEP-128 network..."); +// status = WiFi.begin(ssid, keyIndex, key); + + // attempt to connect using WPA2 encryption: + Serial.println("Attempting to connect to WPA network..."); + status = WiFi.begin(ssid, pass); + + + Serial.print("SSID: "); + Serial.println(ssid); + + // if you're not connected, stop here: + if ( status != WL_CONNECTED) { + Serial.println("Couldn't get a wifi connection"); + while(true); + } + // if you are connected, print out info about the connection: + else { + printIpData(); + printCurrentNet(); + } +} + +void loop() { + // do nothing +} + +void printIpData() { + // print your WiFi shield's IP address: + ip = WiFi.localIP(); + Serial.println(ip); + + + // print your subnet mask: + subnet = WiFi.subnetMask(); + Serial.print("NETMASK: "); + Serial.println(subnet); + + + // print your gateway address: + gateway = WiFi.gatewayIP(); + Serial.print("GATEWAY: "); + Serial.println(gateway); + + // 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); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + Serial.print(bssid[5],HEX); + Serial.print(":"); + 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); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("RSSI:"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption,HEX); +} + +void scanNetworks() { + // scan for nearby networks: + Serial.println("** Scan Networks **"); + byte numSsid = WiFi.scanNetworks(); + + // print the list of networks seen: + Serial.print("SSID List:"); + Serial.println(numSsid); + // print the network number and name for each network found: + for (int thisNet = 0; thisNetthis is a tweet + + This example uses the String library, which is part of the Arduino core from + version 0019. + + Circuit: + * WiFi shield attached to pins 10, 11, 12, 13 + + created 15 Sep 2011 + by Tom Igoe + + This code is in the public domain. + + */ +#include +#include + +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password +int status = WL_IDLE_STATUS; + +// initialize the library instance: +WiFiClient client; + +const int requestInterval = 30*1000; // delay between requests; 30 seconds + +IPAddress server(199,59,149,200); // api.twitter.com + +boolean requested; // whether you've made a request since connecting +long lastAttemptTime = 0; // last time you connected to the server, in milliseconds + +String currentLine = ""; // string to hold the text from server +String tweet = ""; // string to hold the tweet +boolean readingTweet = false; // if you're currently reading the tweet + +void setup() { + // reserve space for the strings: + currentLine.reserve(256); + tweet.reserve(150); + // initialize serial: + Serial.begin(9600); + Serial.println("Attempting to connect to WPA network..."); + Serial.print("SSID: "); + Serial.println(ssid); + + status = WiFi.begin(ssid, pass); + if ( status != WL_CONNECTED) { + Serial.println("Couldn't get a wifi connection"); + while(true); + } + else { + Serial.println("Connected to wifi"); + connectToServer(); + } +} + + + +void loop() +{ + if (client.connected()) { + if (client.available()) { + // read incoming bytes: + char inChar = client.read(); + + // add incoming byte to end of line: + currentLine += inChar; + + // if you get a newline, clear the line: + if (inChar == '\n') { + currentLine = ""; + } + // if the current line ends with , it will + // be followed by the tweet: + if ( currentLine.endsWith("")) { + // tweet is beginning. Clear the tweet string: + readingTweet = true; + tweet = ""; + } + // if you're currently reading the bytes of a tweet, + // add them to the tweet String: + if (readingTweet) { + if (inChar != '<') { + tweet += inChar; + } + else { + // if you got a "<" character, + // you've reached the end of the tweet: + readingTweet = false; + Serial.println(tweet); + // close the connection to the server: + client.stop(); + } + } + } + } + else if (millis() - lastAttemptTime > requestInterval) { + // if you're not connected, and two minutes have passed since + // your last connection, then attempt to connect again: + connectToServer(); + } +} + +void connectToServer() { + // attempt to connect, and wait a millisecond: + Serial.println("connecting to server..."); + if (client.connect(server, 80)) { + Serial.println("making HTTP request..."); + // make HTTP GET request to twitter: + client.println("GET /1/statuses/user_timeline.xml?screen_name=arduinoteam HTTP/1.1"); + client.println("HOST: api.twitter.com"); + client.println(); + } + // note the time of this connect attempt: + lastAttemptTime = millis(); +} + diff --git a/WiFi/examples/WebClientWPA/WebClientWPA.ino b/WiFi/examples/WebClientWPA/WebClientWPA.ino new file mode 100644 index 000000000..4bfca16b8 --- /dev/null +++ b/WiFi/examples/WebClientWPA/WebClientWPA.ino @@ -0,0 +1,77 @@ + +/* + Web client + + This sketch connects to a website (http://www.google.com) + using a WiFi shield. + + Circuit: + * WiFi shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 15 Sep 2011 + by Tom Igoe + */ + + +#include +#include + +char ssid[] = "lamaison"; // your network SSID (name) +char pass[] = "tenantaccess247"; // your network password + +int status = WL_IDLE_STATUS; +IPAddress server(74,125,115,105); // Google + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +WiFiClient client; + +void setup() { + Serial.begin(9600); + Serial.println("Attempting to connect to WPA network..."); + Serial.print("SSID: "); + Serial.println(ssid); + + status = WiFi.begin(ssid, pass); + if ( status != WL_CONNECTED) { + Serial.println("Couldn't get a wifi connection"); + // don't do anything else: + while(true); + } + else { + Serial.println("Connected to wifi"); + Serial.println("\nStarting connection..."); + // if you get a connection, report back via serial: + if (client.connect(server, 80)) { + Serial.println("connected"); + // Make a HTTP request: + client.println("GET /search?q=arduino HTTP/1.0"); + client.println(); + } + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + if (client.available()) { + char c = client.read(); + Serial.print(c); + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + + // do nothing forevermore: + for(;;) + ; + } +} + + diff --git a/WiFi/examples/WebServerWPA/WebServerWPA.ino b/WiFi/examples/WebServerWPA/WebServerWPA.ino new file mode 100644 index 000000000..6dd3138d8 --- /dev/null +++ b/WiFi/examples/WebServerWPA/WebServerWPA.ino @@ -0,0 +1,95 @@ +/* + Web Server + + A simple web server that shows the value of the analog input pins. + using a WiFi shield. + + Circuit: + * WiFi shield attached + * Analog inputs attached to pins A0 through A5 (optional) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 15 Sep 2011 + by Tom Igoe + */ + + +#include +#include + +char ssid[] = "lamaison"; // your network SSID (name) +char pass[] = "tenantaccess247"; // your network password +int status = WL_IDLE_STATUS; + +WiFiServer server(80); + +void setup() { + // initialize serial: + Serial.begin(9600); + Serial.println("Attempting to connect to WPA network..."); + Serial.print("SSID: "); + Serial.println(ssid); + + status = WiFi.begin(ssid, pass); + if ( status != WL_CONNECTED) { + Serial.println("Couldn't get a wifi connection"); + while(true); + } + else { + server.begin(); + Serial.print("Connected to wifi. My address:"); + IPAddress myAddress = WiFi.localIP(); + Serial.println(myAddress); + + } +} + + +void loop() { + // listen for incoming clients + WiFiClient client = server.available(); + if (client) { + // an http request ends with a blank line + boolean currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the http request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard http response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println(); + client.println(""); + // output the value of each analog input pin + for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + client.print("analog input "); + client.print(analogChannel); + client.print(" is "); + client.print(analogRead(analogChannel)); + client.println("
"); + } + client.println(""); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } + else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + // close the connection: + client.stop(); + } +} + + diff --git a/WiFi/examples/PachubeClientString/PachubeClientString.ino b/WiFi/examples/old_examples/PachubeClientString/PachubeClientString.ino similarity index 100% rename from WiFi/examples/PachubeClientString/PachubeClientString.ino rename to WiFi/examples/old_examples/PachubeClientString/PachubeClientString.ino diff --git a/WiFi/examples/Wifi_Open_RSSI/Wifi_Open_RSSI.ino b/WiFi/examples/old_examples/Wifi_Open_RSSI/Wifi_Open_RSSI.ino similarity index 100% rename from WiFi/examples/Wifi_Open_RSSI/Wifi_Open_RSSI.ino rename to WiFi/examples/old_examples/Wifi_Open_RSSI/Wifi_Open_RSSI.ino diff --git a/WiFi/examples/Wifi_Open_ScanNetworks/Wifi_Open_ScanNetworks.ino b/WiFi/examples/old_examples/Wifi_Open_ScanNetworks/Wifi_Open_ScanNetworks.ino similarity index 100% rename from WiFi/examples/Wifi_Open_ScanNetworks/Wifi_Open_ScanNetworks.ino rename to WiFi/examples/old_examples/Wifi_Open_ScanNetworks/Wifi_Open_ScanNetworks.ino diff --git a/WiFi/examples/Wifi_WEP_ScanNetworks/Wifi_WEP_ScanNetworks.ino b/WiFi/examples/old_examples/Wifi_WEP_ScanNetworks/Wifi_WEP_ScanNetworks.ino similarity index 100% rename from WiFi/examples/Wifi_WEP_ScanNetworks/Wifi_WEP_ScanNetworks.ino rename to WiFi/examples/old_examples/Wifi_WEP_ScanNetworks/Wifi_WEP_ScanNetworks.ino diff --git a/WiFi/examples/Wifi_WPA_ChatServer/Wifi_WPA_ChatServer.ino b/WiFi/examples/old_examples/Wifi_WPA_ChatServer/Wifi_WPA_ChatServer.ino similarity index 100% rename from WiFi/examples/Wifi_WPA_ChatServer/Wifi_WPA_ChatServer.ino rename to WiFi/examples/old_examples/Wifi_WPA_ChatServer/Wifi_WPA_ChatServer.ino diff --git a/WiFi/examples/Wifi_WPA_PachubeClientString/Wifi_WPA_PachubeClientString.ino b/WiFi/examples/old_examples/Wifi_WPA_PachubeClientString/Wifi_WPA_PachubeClientString.ino similarity index 100% rename from WiFi/examples/Wifi_WPA_PachubeClientString/Wifi_WPA_PachubeClientString.ino rename to WiFi/examples/old_examples/Wifi_WPA_PachubeClientString/Wifi_WPA_PachubeClientString.ino diff --git a/WiFi/examples/Wifi_WPA_ScanNetworks/Wifi_WPA_ScanNetworks.ino b/WiFi/examples/old_examples/Wifi_WPA_ScanNetworks/Wifi_WPA_ScanNetworks.ino similarity index 100% rename from WiFi/examples/Wifi_WPA_ScanNetworks/Wifi_WPA_ScanNetworks.ino rename to WiFi/examples/old_examples/Wifi_WPA_ScanNetworks/Wifi_WPA_ScanNetworks.ino diff --git a/WiFi/examples/Wifi_WPA_TwitterClient/Wifi_WPA_TwitterClient.ino b/WiFi/examples/old_examples/Wifi_WPA_TwitterClient/Wifi_WPA_TwitterClient.ino similarity index 100% rename from WiFi/examples/Wifi_WPA_TwitterClient/Wifi_WPA_TwitterClient.ino rename to WiFi/examples/old_examples/Wifi_WPA_TwitterClient/Wifi_WPA_TwitterClient.ino diff --git a/WiFi/examples/Wifi_WPA_WebClient/Wifi_WPA_WebClient.ino b/WiFi/examples/old_examples/Wifi_WPA_WebClient/Wifi_WPA_WebClient.ino similarity index 100% rename from WiFi/examples/Wifi_WPA_WebClient/Wifi_WPA_WebClient.ino rename to WiFi/examples/old_examples/Wifi_WPA_WebClient/Wifi_WPA_WebClient.ino diff --git a/WiFi/examples/Wifi_WPA_WebServer/Wifi_WPA_WebServer.ino b/WiFi/examples/old_examples/Wifi_WPA_WebServer/Wifi_WPA_WebServer.ino similarity index 100% rename from WiFi/examples/Wifi_WPA_WebServer/Wifi_WPA_WebServer.ino rename to WiFi/examples/old_examples/Wifi_WPA_WebServer/Wifi_WPA_WebServer.ino diff --git a/WiFi/examples/wifi_Server_example/wifi_Server_example.ino b/WiFi/examples/old_examples/wifi_Server_example/wifi_Server_example.ino similarity index 100% rename from WiFi/examples/wifi_Server_example/wifi_Server_example.ino rename to WiFi/examples/old_examples/wifi_Server_example/wifi_Server_example.ino diff --git a/WiFi/examples/wifi_Server_example_WEP/wifi_Server_example_WEP.ino b/WiFi/examples/old_examples/wifi_Server_example_WEP/wifi_Server_example_WEP.ino similarity index 100% rename from WiFi/examples/wifi_Server_example_WEP/wifi_Server_example_WEP.ino rename to WiFi/examples/old_examples/wifi_Server_example_WEP/wifi_Server_example_WEP.ino diff --git a/WiFi/examples/wifi_Server_example_WPA/wifi_Server_example_WPA.ino b/WiFi/examples/old_examples/wifi_Server_example_WPA/wifi_Server_example_WPA.ino similarity index 100% rename from WiFi/examples/wifi_Server_example_WPA/wifi_Server_example_WPA.ino rename to WiFi/examples/old_examples/wifi_Server_example_WPA/wifi_Server_example_WPA.ino diff --git a/WiFi/examples/wifi_WEP_example/wifi_WEP_example.ino b/WiFi/examples/old_examples/wifi_WEP_example/wifi_WEP_example.ino similarity index 100% rename from WiFi/examples/wifi_WEP_example/wifi_WEP_example.ino rename to WiFi/examples/old_examples/wifi_WEP_example/wifi_WEP_example.ino diff --git a/WiFi/examples/wifi_example/wifi_example.pde b/WiFi/examples/old_examples/wifi_example/wifi_example.pde similarity index 100% rename from WiFi/examples/wifi_example/wifi_example.pde rename to WiFi/examples/old_examples/wifi_example/wifi_example.pde