summaryrefslogtreecommitdiff
path: root/Libraries/WiShield/examples
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries/WiShield/examples')
-rw-r--r--Libraries/WiShield/examples/Flash/Flash.pde89
-rw-r--r--Libraries/WiShield/examples/Flash/webserver.c125
-rw-r--r--Libraries/WiShield/examples/SimpleClient/SimpleClient.pde88
-rw-r--r--Libraries/WiShield/examples/SimpleServer/SimpleServer.pde74
-rw-r--r--Libraries/WiShield/examples/SimpleTweeter/SimpleTweeter.pde79
-rw-r--r--Libraries/WiShield/examples/SocketApp/SocketApp.pde48
-rw-r--r--Libraries/WiShield/examples/SocketApp/socketapp.c118
-rw-r--r--Libraries/WiShield/examples/UDPApp/UDPApp.pde48
-rw-r--r--Libraries/WiShield/examples/UDPApp/udpapp.c137
-rw-r--r--Libraries/WiShield/examples/UDPApp/udpapp.c~137
-rw-r--r--Libraries/WiShield/examples/WebClient/WebClient.pde74
-rw-r--r--Libraries/WiShield/examples/WebClient/webclient.c372
-rw-r--r--Libraries/WiShield/examples/WebServer/WebServer.pde51
-rw-r--r--Libraries/WiShield/examples/WebServer/webserver.c118
14 files changed, 1558 insertions, 0 deletions
diff --git a/Libraries/WiShield/examples/Flash/Flash.pde b/Libraries/WiShield/examples/Flash/Flash.pde
new file mode 100644
index 0000000..1e5ad51
--- /dev/null
+++ b/Libraries/WiShield/examples/Flash/Flash.pde
@@ -0,0 +1,89 @@
+/*
+ * Web Server using Flash
+ *
+ * A simple web server example using the WiShield 2.0
+ * that reads the manufacturing ID from the Flash and
+ * displays it on a webpage.
+ */
+
+#include <WiShield.h>
+#include <dataflash.h>
+
+#define WIRELESS_MODE_INFRA 1
+#define WIRELESS_MODE_ADHOC 2
+
+#define FLASH_SLAVE_SELECT 7
+#define WIFI_SLAVE_SELECT 10
+
+// Wireless configuration parameters ----------------------------------------
+unsigned char local_ip[] = {192,168,1,2}; // IP address of WiShield
+unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
+unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
+const prog_char ssid[] PROGMEM = {"ASYNCLABS"}; // max 32 bytes
+
+unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
+
+// WPA/WPA2 passphrase
+const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters
+
+// WEP 128-bit keys
+// sample HEX keys
+prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
+ };
+
+// setup the wireless mode
+// infrastructure - connect to AP
+// adhoc - connect to another WiFi device
+unsigned char wireless_mode = WIRELESS_MODE_INFRA;
+
+unsigned char ssid_len;
+unsigned char security_passphrase_len;
+//---------------------------------------------------------------------------
+
+unsigned char mfg_id[4];
+
+void setup()
+{
+ initShield();
+}
+
+// This is the webpage that is served up by the webserver
+const prog_char webpage[] PROGMEM = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"
+ "<html><body style=\"margin:100px\">"
+ "<center>"
+ "<h1>Flash Mfg ID: 000 000 000</h1>"
+ "<form method=post action=\"/upload\" enctype=\"multipart/form-data\">"
+ "<b>FS Image Upload</b>"
+ "<p>"
+ "<input type=file name=i size=40> &nbsp; <input type=submit value=\"Upload\">"
+ "</form>"
+ "</center>"
+ "</body></html>";
+
+void loop()
+{
+ dflash.read_id(mfg_id);
+
+ WiFi.run();
+}
+
+void initShield()
+{
+ // there is some contention on the SPI between the flash and wifi chip,
+ // so disable both devices at the beginning until they are properly
+ // initialized by their respective libraries
+ pinMode(FLASH_SLAVE_SELECT, OUTPUT);
+ digitalWrite(FLASH_SLAVE_SELECT, HIGH);
+ pinMode(WIFI_SLAVE_SELECT, OUTPUT);
+ digitalWrite(WIFI_SLAVE_SELECT, HIGH);
+
+ // now init dataflash
+ dflash.init(FLASH_SLAVE_SELECT);
+
+ // now init wifi
+ WiFi.init();
+}
+
diff --git a/Libraries/WiShield/examples/Flash/webserver.c b/Libraries/WiShield/examples/Flash/webserver.c
new file mode 100644
index 0000000..045b843
--- /dev/null
+++ b/Libraries/WiShield/examples/Flash/webserver.c
@@ -0,0 +1,125 @@
+
+/******************************************************************************
+
+ Filename: webserver.h
+ Description: Webserver app for the WiShield 1.0
+
+ ******************************************************************************
+
+ TCP/IP stack and driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
+ <asynclabs@asynclabs.com>
+
+ Author Date Comment
+ ---------------------------------------------------------------
+ AsyncLabs 05/29/2009 Initial version
+
+ *****************************************************************************/
+
+#include "uip.h"
+#include <string.h>
+#include "webserver.h"
+#include "config.h"
+
+static int handle_connection(struct webserver_state *s);
+
+void webserver_init(void)
+{
+ uip_listen(HTONS(80));
+}
+
+void webserver_appcall(void)
+{
+ struct webserver_state *s = &(uip_conn->appstate);
+
+ if(uip_connected()) {
+ PSOCK_INIT(&s->p, s->inputbuf, sizeof(s->inputbuf));
+ }
+
+ handle_connection(s);
+}
+
+#define ISO_nl 0x0a
+#define ISO_space 0x20
+#define ISO_slash 0x2f
+
+const char http_get[5] = {0x47, 0x45, 0x54, 0x20, }; /* "GET " */
+
+unsigned short fill_buf(void* blk)
+{
+ unsigned short webpage_len;
+ char int_string[4];
+
+ webpage_len = (strlen_P(webpage)>uip_mss())?uip_mss():strlen_P(webpage);
+
+ memcpy_P(uip_appdata, webpage, webpage_len);
+
+ sprintf(int_string, "%X", mfg_id[0]);
+ memcpy(&uip_appdata[104], int_string, 2);
+ sprintf(int_string, "%X", mfg_id[1]);
+ memcpy(&uip_appdata[108], int_string, 2);
+
+ return webpage_len;
+}
+
+static int handle_connection(struct webserver_state *s)
+{
+ PSOCK_BEGIN(&s->p);
+
+ // the incoming GET request will have the following format:
+ // GET / HTTP/1.1 ....
+ // we have to parse this string to determine the resource being requested
+ // if the requested resource is not the root webpage ('/') then,
+ // GET /<resource name> HTTP/1.1 ....
+ // we should parse the specific resource and react appropriately
+
+ // read incoming data until we read a space character
+ PSOCK_READTO(&s->p, ISO_space);
+
+ // parse the data to determine if it was a GET request
+ if(strncmp(s->inputbuf, http_get, 4) != 0) {
+ PSOCK_CLOSE_EXIT(&s->p);
+ }
+
+ // continue reading until the next space character
+ PSOCK_READTO(&s->p, ISO_space);
+
+ // determine the requested resource
+ // in this case, we check if the request was for the '/' root page
+ // AKA index.html
+ if(s->inputbuf[0] != ISO_slash) {
+ // request for unknown webpage, close and exit
+ PSOCK_CLOSE_EXIT(&s->p);
+ }
+
+ if(s->inputbuf[1] != ISO_space) {
+ // request for unavailable resource
+ // not supported, modify to add support for additional resources
+ PSOCK_CLOSE_EXIT(&s->p);
+ }
+
+ //PSOCK_SEND_STR(&s->p, "HTTP/1.1 200 OK\r\n");
+ //PSOCK_SEND_STR(&s->p, "Content-Type: text/html\r\n");
+ //PSOCK_SEND_STR(&s->p, "\r\n");
+ //PSOCK_SEND_STR(&s->p, "Hello World, I am WiShield");
+ //PSOCK_SEND_STR(&s->p, "<center><h1>Hello World!! I am WiShield</h1></center>");
+ PSOCK_GENERATOR_SEND(&s->p, fill_buf, 0);
+ PSOCK_CLOSE(&s->p);
+ PSOCK_END(&s->p);
+}
diff --git a/Libraries/WiShield/examples/SimpleClient/SimpleClient.pde b/Libraries/WiShield/examples/SimpleClient/SimpleClient.pde
new file mode 100644
index 0000000..52c9e56
--- /dev/null
+++ b/Libraries/WiShield/examples/SimpleClient/SimpleClient.pde
@@ -0,0 +1,88 @@
+/*
+ * A simple sketch that uses WiServer to get the hourly weather data from LAX and prints
+ * it via the Serial API
+ */
+
+#include <WiServer.h>
+
+#define WIRELESS_MODE_INFRA 1
+#define WIRELESS_MODE_ADHOC 2
+
+// Wireless configuration parameters ----------------------------------------
+unsigned char local_ip[] = {192,168,1,2}; // IP address of WiShield
+unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
+unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
+const prog_char ssid[] PROGMEM = {"ASYNCLABS"}; // max 32 bytes
+
+unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
+
+// WPA/WPA2 passphrase
+const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters
+
+// WEP 128-bit keys
+// sample HEX keys
+prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
+ };
+
+// setup the wireless mode
+// infrastructure - connect to AP
+// adhoc - connect to another WiFi device
+unsigned char wireless_mode = WIRELESS_MODE_INFRA;
+
+unsigned char ssid_len;
+unsigned char security_passphrase_len;
+// End of wireless configuration parameters ----------------------------------------
+
+
+// Function that prints data from the server
+void printData(char* data, int len) {
+
+ // Print the data returned by the server
+ // Note that the data is not null-terminated, may be broken up into smaller packets, and
+ // includes the HTTP header.
+ while (len-- > 0) {
+ Serial.print(*(data++));
+ }
+}
+
+
+// IP Address for www.weather.gov
+uint8 ip[] = {140,90,113,200};
+
+// A request that gets the latest METAR weather data for LAX
+GETrequest getWeather(ip, 80, "www.weather.gov", "/data/METAR/KLAX.1.txt");
+
+
+void setup() {
+ // Initialize WiServer (we'll pass NULL for the page serving function since we don't need to serve web pages)
+ WiServer.init(NULL);
+
+ // Enable Serial output and ask WiServer to generate log messages (optional)
+ Serial.begin(57600);
+ WiServer.enableVerboseMode(true);
+
+ // Have the processData function called when data is returned by the server
+ getWeather.setReturnFunc(printData);
+}
+
+
+// Time (in millis) when the data should be retrieved
+long updateTime = 0;
+
+void loop(){
+
+ // Check if it's time to get an update
+ if (millis() >= updateTime) {
+ getWeather.submit();
+ // Get another update one hour from now
+ updateTime += 1000 * 60 * 60;
+ }
+
+ // Run WiServer
+ WiServer.server_task();
+
+ delay(10);
+}
diff --git a/Libraries/WiShield/examples/SimpleServer/SimpleServer.pde b/Libraries/WiShield/examples/SimpleServer/SimpleServer.pde
new file mode 100644
index 0000000..aeb9288
--- /dev/null
+++ b/Libraries/WiShield/examples/SimpleServer/SimpleServer.pde
@@ -0,0 +1,74 @@
+/*
+ * A simple sketch that uses WiServer to serve a web page
+ */
+
+
+#include <WiServer.h>
+
+#define WIRELESS_MODE_INFRA 1
+#define WIRELESS_MODE_ADHOC 2
+
+// Wireless configuration parameters ----------------------------------------
+unsigned char local_ip[] = {192,168,1,2}; // IP address of WiShield
+unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
+unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
+const prog_char ssid[] PROGMEM = {"ASYNCLABS"}; // max 32 bytes
+
+unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
+
+// WPA/WPA2 passphrase
+const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters
+
+// WEP 128-bit keys
+// sample HEX keys
+prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
+ };
+
+// setup the wireless mode
+// infrastructure - connect to AP
+// adhoc - connect to another WiFi device
+unsigned char wireless_mode = WIRELESS_MODE_INFRA;
+
+unsigned char ssid_len;
+unsigned char security_passphrase_len;
+// End of wireless configuration parameters ----------------------------------------
+
+
+// This is our page serving function that generates web pages
+boolean sendMyPage(char* URL) {
+
+ // Check if the requested URL matches "/"
+ if (strcmp(URL, "/") == 0) {
+ // Use WiServer's print and println functions to write out the page content
+ WiServer.print("<html>");
+ WiServer.print("Hello World!");
+ WiServer.print("</html>");
+
+ // URL was recognized
+ return true;
+ }
+ // URL not found
+ return false;
+}
+
+
+void setup() {
+ // Initialize WiServer and have it use the sendMyPage function to serve pages
+ WiServer.init(sendMyPage);
+
+ // Enable Serial output and ask WiServer to generate log messages (optional)
+ Serial.begin(57600);
+ WiServer.enableVerboseMode(true);
+}
+
+void loop(){
+
+ // Run WiServer
+ WiServer.server_task();
+
+ delay(10);
+}
+
diff --git a/Libraries/WiShield/examples/SimpleTweeter/SimpleTweeter.pde b/Libraries/WiShield/examples/SimpleTweeter/SimpleTweeter.pde
new file mode 100644
index 0000000..d7b6caf
--- /dev/null
+++ b/Libraries/WiShield/examples/SimpleTweeter/SimpleTweeter.pde
@@ -0,0 +1,79 @@
+/*
+ * A simple sketch that uses WiServer to send a tweet with the current system time every 5 minutes
+ */
+
+#include <WiServer.h>
+
+#define WIRELESS_MODE_INFRA 1
+#define WIRELESS_MODE_ADHOC 2
+
+// Wireless configuration parameters ----------------------------------------
+unsigned char local_ip[] = {192,168,1,2}; // IP address of WiShield
+unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
+unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
+const prog_char ssid[] PROGMEM = {"ASYNCLABS"}; // max 32 bytes
+
+unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
+
+// WPA/WPA2 passphrase
+const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters
+
+// WEP 128-bit keys
+// sample HEX keys
+prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
+ };
+
+// setup the wireless mode
+// infrastructure - connect to AP
+// adhoc - connect to another WiFi device
+unsigned char wireless_mode = WIRELESS_MODE_INFRA;
+
+unsigned char ssid_len;
+unsigned char security_passphrase_len;
+// End of wireless configuration parameters ----------------------------------------
+
+
+// Auth string for the Twitter account
+char* auth = "[YOUR DATA HERE]"; // Base64 encoded USERNAME:PASSWORD
+
+
+// This function generates a message with the current system time
+void currentTime() {
+ WiServer.print("Arduino has been running for ");
+ WiServer.printTime(millis());
+}
+
+// A request that sends a Tweet using the currentTime function
+TWEETrequest sentMyTweet(auth, currentTime);
+
+
+void setup() {
+ // Initialize WiServer (we'll pass NULL for the page serving function since we don't need to serve web pages)
+ WiServer.init(NULL);
+
+ // Enable Serial output and ask WiServer to generate log messages (optional)
+ Serial.begin(57600);
+ WiServer.enableVerboseMode(true);
+}
+
+
+// Time (in millis) when the next tweet should be sent
+long tweetTime = 0;
+
+void loop(){
+
+ // Check if it's time to sent a tweet
+ if (millis() >= tweetTime) {
+ sentMyTweet.submit();
+ // Send next tweet 5 minutes from now
+ tweetTime += 1000 * 60 * 5;
+ }
+
+ // Run WiServer
+ WiServer.server_task();
+
+ delay(10);
+}
diff --git a/Libraries/WiShield/examples/SocketApp/SocketApp.pde b/Libraries/WiShield/examples/SocketApp/SocketApp.pde
new file mode 100644
index 0000000..662bc07
--- /dev/null
+++ b/Libraries/WiShield/examples/SocketApp/SocketApp.pde
@@ -0,0 +1,48 @@
+/*
+ * Socket App
+ *
+ * A simple socket application example using the WiShield 1.0
+ */
+
+#include <WiShield.h>
+
+#define WIRELESS_MODE_INFRA 1
+#define WIRELESS_MODE_ADHOC 2
+
+// Wireless configuration parameters ----------------------------------------
+unsigned char local_ip[] = {192,168,1,2}; // IP address of WiShield
+unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
+unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
+const prog_char ssid[] PROGMEM = {"ASYNCLABS"}; // max 32 bytes
+
+unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
+
+// WPA/WPA2 passphrase
+const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters
+
+// WEP 128-bit keys
+// sample HEX keys
+prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
+ };
+
+// setup the wireless mode
+// infrastructure - connect to AP
+// adhoc - connect to another WiFi device
+unsigned char wireless_mode = WIRELESS_MODE_INFRA;
+
+unsigned char ssid_len;
+unsigned char security_passphrase_len;
+//---------------------------------------------------------------------------
+
+void setup()
+{
+ WiFi.init();
+}
+
+void loop()
+{
+ WiFi.run();
+}
diff --git a/Libraries/WiShield/examples/SocketApp/socketapp.c b/Libraries/WiShield/examples/SocketApp/socketapp.c
new file mode 100644
index 0000000..c815560
--- /dev/null
+++ b/Libraries/WiShield/examples/SocketApp/socketapp.c
@@ -0,0 +1,118 @@
+
+/******************************************************************************
+
+ Filename: socketapp.c
+ Description: Simple socket programming example for the WiShield 1.0
+
+ ******************************************************************************
+
+ TCP/IP stack and driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
+ <asynclabs@asynclabs.com>
+
+ Author Date Comment
+ ---------------------------------------------------------------
+ AsyncLabs 06/06/2009 Initial version
+
+ *****************************************************************************/
+
+/*
+ * This is a short example of how to write uIP applications using
+ * protosockets.
+ */
+
+/*
+ * We define the application state (struct socket_app_state) in the
+ * socketapp.h file, so we need to include it here. We also include
+ * uip.h (since this cannot be included in socketapp.h) and
+ * <string.h>, since we use the memcpy() function in the code.
+ */
+#include "socketapp.h"
+#include "uip.h"
+#include <string.h>
+
+/*
+ * Declaration of the protosocket function that handles the connection
+ * (defined at the end of the code).
+ */
+static int handle_connection(struct socket_app_state *s);
+/*---------------------------------------------------------------------------*/
+/*
+ * The initialization function. We must explicitly call this function
+ * from the system initialization code, some time after uip_init() is
+ * called.
+ */
+void socket_app_init(void)
+{
+ /* We start to listen for connections on TCP port 1000. */
+ uip_listen(HTONS(1000));
+}
+/*---------------------------------------------------------------------------*/
+/*
+ * In socketapp.h we have defined the UIP_APPCALL macro to
+ * socket_app_appcall so that this function is uIP's application
+ * function. This function is called whenever an uIP event occurs
+ * (e.g. when a new connection is established, new data arrives, sent
+ * data is acknowledged, data needs to be retransmitted, etc.).
+ */
+void socket_app_appcall(void)
+{
+ /*
+ * The uip_conn structure has a field called "appstate" that holds
+ * the application state of the connection. We make a pointer to
+ * this to access it easier.
+ */
+ struct socket_app_state *s = &(uip_conn->appstate);
+
+ /*
+ * If a new connection was just established, we should initialize
+ * the protosocket in our applications' state structure.
+ */
+ if(uip_connected()) {
+ PSOCK_INIT(&s->p, s->inputbuffer, sizeof(s->inputbuffer));
+ }
+
+ /*
+ * Finally, we run the protosocket function that actually handles
+ * the communication. We pass it a pointer to the application state
+ * of the current connection.
+ */
+ handle_connection(s);
+}
+/*---------------------------------------------------------------------------*/
+/*
+ * This is the protosocket function that handles the communication. A
+ * protosocket function must always return an int, but must never
+ * explicitly return - all return statements are hidden in the PSOCK
+ * macros.
+ */
+static int handle_connection(struct socket_app_state *s)
+{
+ PSOCK_BEGIN(&s->p);
+
+ PSOCK_SEND_STR(&s->p, "Hello. What is you name?\n");
+ PSOCK_READTO(&s->p, '\n');
+ PSOCK_SEND_STR(&s->p, "Hello ");
+ PSOCK_SEND_STR(&s->p, s->inputbuffer);
+ memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
+ PSOCK_CLOSE(&s->p);
+
+ PSOCK_END(&s->p);
+}
+/*---------------------------------------------------------------------------*/
diff --git a/Libraries/WiShield/examples/UDPApp/UDPApp.pde b/Libraries/WiShield/examples/UDPApp/UDPApp.pde
new file mode 100644
index 0000000..92a0cf1
--- /dev/null
+++ b/Libraries/WiShield/examples/UDPApp/UDPApp.pde
@@ -0,0 +1,48 @@
+/*
+ * UDP endpoint
+ *
+ * A simple UDP endpoint example using the WiShield 1.0
+ */
+
+#include <WiShield.h>
+
+#define WIRELESS_MODE_INFRA 1
+#define WIRELESS_MODE_ADHOC 2
+
+// Wireless configuration parameters ----------------------------------------
+unsigned char local_ip[] = {192,168,1,2}; // IP address of WiShield
+unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
+unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
+const prog_char ssid[] PROGMEM = {"ASYNCLABS"}; // max 32 bytes
+
+unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
+
+// WPA/WPA2 passphrase
+const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters
+
+// WEP 128-bit keys
+// sample HEX keys
+prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
+ };
+
+// setup the wireless mode
+// infrastructure - connect to AP
+// adhoc - connect to another WiFi device
+unsigned char wireless_mode = WIRELESS_MODE_INFRA;
+
+unsigned char ssid_len;
+unsigned char security_passphrase_len;
+//---------------------------------------------------------------------------
+
+void setup()
+{
+ WiFi.init();
+}
+
+void loop()
+{
+ WiFi.run();
+}
diff --git a/Libraries/WiShield/examples/UDPApp/udpapp.c b/Libraries/WiShield/examples/UDPApp/udpapp.c
new file mode 100644
index 0000000..cdf2d28
--- /dev/null
+++ b/Libraries/WiShield/examples/UDPApp/udpapp.c
@@ -0,0 +1,137 @@
+
+/******************************************************************************
+
+ Filename: udpapp.h
+ Description: UDP app for the WiShield 1.0
+
+ ******************************************************************************
+
+ TCP/IP stack and driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
+ <asynclabs@asynclabs.com>
+
+ Author Date Comment
+ ---------------------------------------------------------------
+ AsyncLabs 07/11/2009 Initial version
+
+ *****************************************************************************/
+
+#include "uip.h"
+#include <string.h>
+#include "udpapp.h"
+#include "config.h"
+
+#define STATE_INIT 0
+#define STATE_LISTENING 1
+#define STATE_HELLO_RECEIVED 2
+#define STATE_NAME_RECEIVED 3
+
+static struct udpapp_state s;
+
+void dummy_app_appcall(void)
+{
+}
+
+void udpapp_init(void)
+{
+ uip_ipaddr_t addr;
+ struct uip_udp_conn *c;
+
+ uip_ipaddr(&addr, 192,168,1,23);
+ c = uip_udp_new(&addr, HTONS(0));
+ if(c != NULL) {
+ uip_udp_bind(c, HTONS(12344));
+ }
+
+ s.state = STATE_INIT;
+
+ PT_INIT(&s.pt);
+}
+
+static unsigned char parse_msg(void)
+{
+ if (memcmp(uip_appdata, "Hello", 5) == 0) {
+ return 1;
+ }
+
+ return 0;
+}
+
+static void send_request(void)
+{
+ char str[] = "Hello. What is your name?\n";
+
+ memcpy(uip_appdata, str, strlen(str));
+ uip_send(uip_appdata, strlen(str));
+}
+
+static void send_response(void)
+{
+ char i = 0;
+ char str[] = "Hello ";
+
+ while ( ( ((char*)uip_appdata)[i] != '\n') && i < 9) {
+ s.inputbuf[i] = ((char*)uip_appdata)[i];
+ i++;
+ }
+ s.inputbuf[i] = '\n';
+
+ memcpy(uip_appdata, str, 6);
+ memcpy(uip_appdata+6, s.inputbuf, i+1);
+ uip_send(uip_appdata, i+7);
+}
+
+static PT_THREAD(handle_connection(void))
+{
+ PT_BEGIN(&s.pt);
+
+ s.state = STATE_LISTENING;
+
+ do {
+ PT_WAIT_UNTIL(&s.pt, uip_newdata());
+
+ if(uip_newdata() && parse_msg()) {
+ s.state = STATE_HELLO_RECEIVED;
+ uip_flags &= (~UIP_NEWDATA);
+ break;
+ }
+ } while(s.state != STATE_HELLO_RECEIVED);
+
+ do {
+ send_request();
+ PT_WAIT_UNTIL(&s.pt, uip_newdata());
+
+ if(uip_newdata()) {
+ s.state = STATE_NAME_RECEIVED;
+ uip_flags &= (~UIP_NEWDATA);
+ break;
+ }
+ } while(s.state != STATE_NAME_RECEIVED);
+
+ send_response();
+
+ s.state = STATE_INIT;
+
+ PT_END(&s.pt);
+}
+
+void udpapp_appcall(void)
+{
+ handle_connection();
+}
diff --git a/Libraries/WiShield/examples/UDPApp/udpapp.c~ b/Libraries/WiShield/examples/UDPApp/udpapp.c~
new file mode 100644
index 0000000..f019164
--- /dev/null
+++ b/Libraries/WiShield/examples/UDPApp/udpapp.c~
@@ -0,0 +1,137 @@
+
+/******************************************************************************
+
+ Filename: udpapp.h
+ Description: UDP app for the WiShield 1.0
+
+ ******************************************************************************
+
+ TCP/IP stack and driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
+ <asynclabs@asynclabs.com>
+
+ Author Date Comment
+ ---------------------------------------------------------------
+ AsyncLabs 07/11/2009 Initial version
+
+ *****************************************************************************/
+
+#include "uip.h"
+#include <string.h>
+#include "udpapp.h"
+#include "config.h"
+
+#define STATE_INIT 0
+#define STATE_LISTENING 1
+#define STATE_HELLO_RECEIVED 2
+#define STATE_NAME_RECEIVED 3
+
+static struct udpapp_state s;
+
+void dummy_app_appcall(void)
+{
+}
+
+void udpapp_init(void)
+{
+ uip_ipaddr_t addr;
+ struct uip_udp_conn *c;
+
+ uip_ipaddr(&addr, 192,168,1,100);
+ c = uip_udp_new(&addr, HTONS(0));
+ if(c != NULL) {
+ uip_udp_bind(c, HTONS(12344));
+ }
+
+ s.state = STATE_INIT;
+
+ PT_INIT(&s.pt);
+}
+
+static unsigned char parse_msg(void)
+{
+ if (memcmp(uip_appdata, "Hello", 5) == 0) {
+ return 1;
+ }
+
+ return 0;
+}
+
+static void send_request(void)
+{
+ char str[] = "Hello. What is your name?\n";
+
+ memcpy(uip_appdata, str, strlen(str));
+ uip_send(uip_appdata, strlen(str));
+}
+
+static void send_response(void)
+{
+ char i = 0;
+ char str[] = "Hello ";
+
+ while ( ( ((char*)uip_appdata)[i] != '\n') && i < 9) {
+ s.inputbuf[i] = ((char*)uip_appdata)[i];
+ i++;
+ }
+ s.inputbuf[i] = '\n';
+
+ memcpy(uip_appdata, str, 6);
+ memcpy(uip_appdata+6, s.inputbuf, i+1);
+ uip_send(uip_appdata, i+7);
+}
+
+static PT_THREAD(handle_connection(void))
+{
+ PT_BEGIN(&s.pt);
+
+ s.state = STATE_LISTENING;
+
+ do {
+ PT_WAIT_UNTIL(&s.pt, uip_newdata());
+
+ if(uip_newdata() && parse_msg()) {
+ s.state = STATE_HELLO_RECEIVED;
+ uip_flags &= (~UIP_NEWDATA);
+ break;
+ }
+ } while(s.state != STATE_HELLO_RECEIVED);
+
+ do {
+ send_request();
+ PT_WAIT_UNTIL(&s.pt, uip_newdata());
+
+ if(uip_newdata()) {
+ s.state = STATE_NAME_RECEIVED;
+ uip_flags &= (~UIP_NEWDATA);
+ break;
+ }
+ } while(s.state != STATE_NAME_RECEIVED);
+
+ send_response();
+
+ s.state = STATE_INIT;
+
+ PT_END(&s.pt);
+}
+
+void udpapp_appcall(void)
+{
+ handle_connection();
+}
diff --git a/Libraries/WiShield/examples/WebClient/WebClient.pde b/Libraries/WiShield/examples/WebClient/WebClient.pde
new file mode 100644
index 0000000..53e243c
--- /dev/null
+++ b/Libraries/WiShield/examples/WebClient/WebClient.pde
@@ -0,0 +1,74 @@
+/*
+ * Web Client
+ *
+ * A simple web client example using the WiShield 1.0
+ */
+
+#include <WiShield.h>
+
+#define WIRELESS_MODE_INFRA 1
+#define WIRELESS_MODE_ADHOC 2
+
+// Wireless configuration parameters ----------------------------------------
+unsigned char local_ip[] = {192,168,1,2}; // IP address of WiShield
+unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
+unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
+const prog_char ssid[] PROGMEM = {"ASYNCLABS"}; // max 32 bytes
+
+unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
+
+// WPA/WPA2 passphrase
+const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters
+
+// WEP 128-bit keys
+// sample HEX keys
+prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
+ };
+
+// setup the wireless mode
+// infrastructure - connect to AP
+// adhoc - connect to another WiFi device
+unsigned char wireless_mode = WIRELESS_MODE_INFRA;
+
+unsigned char ssid_len;
+unsigned char security_passphrase_len;
+//---------------------------------------------------------------------------
+
+void setup()
+{
+ WiFi.init();
+}
+
+unsigned char loop_cnt = 0;
+
+// The stack does not have support for DNS and therefore cannot resolve
+// host names. It needs actual IP addresses of the servers. This info
+// can be obtained by executing, for example, $ ping twitter.com on
+// a terminal on your PC
+//char google_ip[] = {74,125,67,100}; // Google
+char twitter_ip[] = {128,121,146,100}; // Twitter
+
+// This string can be used to send a request to Twitter.com to update your status
+// It will need a valid Authorization string which can be derived from your
+// Twitter.com username and password using Base64 algorithm
+// See, http://en.wikipedia.org/wiki/Basic_access_authentication
+// You need to replace <-!!-Authorization String-!!-> with a valid string before
+// using this sample sketch.
+// The Content-Length variable should equal the length of the data string
+// In the example below, "Content-Length: 21" corresponds to "status=Ready to sleep"
+const prog_char twitter[] PROGMEM = {"POST /statuses/update.xml HTTP/1.1\r\nAuthorization: Basic <-!!-Authorization String-!!->\r\nUser-Agent: uIP/1.0\r\nHost: twitter.com\r\nContent-Length: 21\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\nstatus=Ready to sleep"};
+
+void loop()
+{
+ // if this is the first iteration
+ // send the request
+ if (loop_cnt == 0) {
+ webclient_get(twitter_ip, 80, "/");
+ loop_cnt = 1;
+ }
+
+ WiFi.run();
+}
diff --git a/Libraries/WiShield/examples/WebClient/webclient.c b/Libraries/WiShield/examples/WebClient/webclient.c
new file mode 100644
index 0000000..19fae3a
--- /dev/null
+++ b/Libraries/WiShield/examples/WebClient/webclient.c
@@ -0,0 +1,372 @@
+
+/******************************************************************************
+
+ Filename: webclient.c
+ Description: Webclient app for the WiShield 1.0
+
+ ******************************************************************************
+
+ TCP/IP stack and driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
+ <asynclabs@asynclabs.com>
+
+ Author Date Comment
+ ---------------------------------------------------------------
+ AsyncLabs 05/29/2009 Initial version
+
+ *****************************************************************************/
+
+#include "uip.h"
+#include "uiplib.h"
+#include "webclient.h"
+#include "config.h"
+
+#include <string.h>
+
+#define WEBCLIENT_TIMEOUT 100
+
+#define WEBCLIENT_STATE_STATUSLINE 0
+#define WEBCLIENT_STATE_HEADERS 1
+#define WEBCLIENT_STATE_DATA 2
+#define WEBCLIENT_STATE_CLOSE 3
+
+#define HTTPFLAG_NONE 0
+#define HTTPFLAG_OK 1
+#define HTTPFLAG_MOVED 2
+#define HTTPFLAG_ERROR 3
+
+
+#define ISO_nl 0x0a
+#define ISO_cr 0x0d
+
+static struct webclient_state s;
+
+const char http_11[9] =
+ /* "HTTP/1.1" */
+{0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0 };
+const char http_200[5] =
+ /* "200 " */
+{0x32, 0x30, 0x30, 0x20, 0 };
+const char http_301[5] =
+ /* "301 " */
+{0x33, 0x30, 0x31, 0x20, 0 };
+const char http_302[5] =
+ /* "302 " */
+{0x33, 0x30, 0x32, 0x20, 0 };
+
+/*-----------------------------------------------------------------------------------*/
+char* webclient_mimetype(void)
+{
+ return s.mimetype;
+}
+/*-----------------------------------------------------------------------------------*/
+char* webclient_filename(void)
+{
+ return s.file;
+}
+/*-----------------------------------------------------------------------------------*/
+char* webclient_hostname(void)
+{
+ return s.host;
+}
+/*-----------------------------------------------------------------------------------*/
+unsigned short webclient_port(void)
+{
+ return s.port;
+}
+/*-----------------------------------------------------------------------------------*/
+void webclient_init(void)
+{
+
+}
+/*-----------------------------------------------------------------------------------*/
+static void init_connection(void)
+{
+ s.state = WEBCLIENT_STATE_STATUSLINE;
+
+ // set the length of the client string to be transmitted
+ s.getrequestleft = strlen_P(twitter);
+
+ s.getrequestptr = 0;
+
+ s.httpheaderlineptr = 0;
+}
+/*-----------------------------------------------------------------------------------*/
+void webclient_close(void)
+{
+ s.state = WEBCLIENT_STATE_CLOSE;
+}
+/*-----------------------------------------------------------------------------------*/
+unsigned char webclient_get(char *host, u16_t port, char *file)
+{
+ struct uip_conn *conn;
+ uip_ipaddr_t ipaddr;
+
+ uip_ipaddr(&ipaddr, host[0],host[1],host[2],host[3]);
+
+ conn = uip_connect(&ipaddr, htons(port));
+
+ if(conn == NULL) {
+ return 0;
+ }
+
+ s.port = port;
+ strncpy(s.file, file, sizeof(s.file));
+ strncpy(s.host, host, sizeof(s.host));
+
+ init_connection();
+ return 1;
+}
+/*-----------------------------------------------------------------------------------*/
+static unsigned char* copy_string(unsigned char *dest, const unsigned char *src, unsigned char len)
+{
+ strncpy(dest, src, len);
+ return dest + len;
+}
+/*-----------------------------------------------------------------------------------*/
+static void senddata(void)
+{
+ u16_t len;
+ char *getrequest;
+ char *cptr;
+
+ if(s.getrequestleft > 0) {
+ cptr = getrequest = (char *)uip_appdata;
+
+#if 0
+ cptr = copy_string(cptr, http_get, sizeof(http_get) - 1);
+ cptr = copy_string(cptr, s.file, strlen(s.file));
+ *cptr++ = ISO_space;
+ cptr = copy_string(cptr, http_10, sizeof(http_10) - 1);
+
+ cptr = copy_string(cptr, http_crnl, sizeof(http_crnl) - 1);
+
+ cptr = copy_string(cptr, http_host, sizeof(http_host) - 1);
+ cptr = copy_string(cptr, s.host, strlen(s.host));
+ cptr = copy_string(cptr, http_crnl, sizeof(http_crnl) - 1);
+
+ cptr = copy_string(cptr, http_user_agent_fields,
+ strlen(http_user_agent_fields));
+#endif
+
+ // copy the client transmit string into the TX buffer
+ memcpy_P(cptr, twitter, strlen_P(twitter));
+
+ len = s.getrequestleft > uip_mss()?uip_mss():s.getrequestleft;
+ uip_send(&(getrequest[s.getrequestptr]), len);
+ }
+}
+/*-----------------------------------------------------------------------------------*/
+static void acked(void)
+{
+ u16_t len;
+
+ if(s.getrequestleft > 0) {
+ len = s.getrequestleft > uip_mss()?uip_mss():s.getrequestleft;
+ s.getrequestleft -= len;
+ s.getrequestptr += len;
+ }
+}
+/*-----------------------------------------------------------------------------------*/
+static u16_t parse_statusline(u16_t len)
+{
+ char *cptr;
+ char* temp;
+
+ while(len > 0 && s.httpheaderlineptr < sizeof(s.httpheaderline)) {
+ s.httpheaderline[s.httpheaderlineptr] = *(char *)uip_appdata;
+ //((char *)uip_appdata)++;
+ temp = (char *)uip_appdata;
+ temp++;
+ uip_appdata = temp;
+ --len;
+ if(s.httpheaderline[s.httpheaderlineptr] == ISO_nl) {
+
+ if((strncmp(s.httpheaderline, http_11,sizeof(http_11) - 1) == 0)) {
+ cptr = &(s.httpheaderline[9]);
+ s.httpflag = HTTPFLAG_NONE;
+ if(strncmp(cptr, http_200, sizeof(http_200) - 1) == 0) {
+ /* 200 OK */
+ s.httpflag = HTTPFLAG_OK;
+ }
+ else if(strncmp(cptr, http_301, sizeof(http_301) - 1) == 0 ||
+ strncmp(cptr, http_302, sizeof(http_302) - 1) == 0) {
+ /* 301 Moved permanently or 302 Found. Location: header line
+ * will contain the new location. */
+ s.httpflag = HTTPFLAG_MOVED;
+ }
+ else {
+ s.httpheaderline[s.httpheaderlineptr - 1] = 0;
+ }
+ }
+ else {
+ uip_abort();
+ webclient_aborted();
+ return 0;
+ }
+
+ /* We're done parsing the status line, so we reset the pointer
+ * and start parsing the HTTP headers.*/
+ s.httpheaderlineptr = 0;
+ s.state = WEBCLIENT_STATE_HEADERS;
+ break;
+ }
+ else {
+ ++s.httpheaderlineptr;
+ }
+ }
+ return len;
+}
+/*-----------------------------------------------------------------------------------*/
+static u16_t parse_headers(u16_t len)
+{
+ char *cptr;
+ static unsigned char i;
+ char* temp;
+
+ while(len > 0 && s.httpheaderlineptr < sizeof(s.httpheaderline)) {
+ s.httpheaderline[s.httpheaderlineptr] = *(char *)uip_appdata;
+ //++((char *)uip_appdata);
+ temp = (char *)uip_appdata;
+ temp++;
+ uip_appdata = temp;
+ --len;
+ if(s.httpheaderline[s.httpheaderlineptr] == ISO_nl) {
+ /* We have an entire HTTP header line in s.httpheaderline, so
+ * we parse it. */
+ if(s.httpheaderline[0] == ISO_cr) {
+ /* This was the last header line (i.e., and empty "\r\n"), so
+ * we are done with the headers and proceed with the actual
+ * data. */
+ s.state = WEBCLIENT_STATE_DATA;
+ return len;
+ }
+
+ /* We're done parsing, so we reset the pointer and start the
+ * next line. */
+ s.httpheaderlineptr = 0;
+ }
+ else {
+ ++s.httpheaderlineptr;
+ }
+ }
+
+ return len;
+}
+/*-----------------------------------------------------------------------------------*/
+static void newdata(void)
+{
+ u16_t len;
+
+ len = uip_datalen();
+
+ if(s.state == WEBCLIENT_STATE_STATUSLINE) {
+ len = parse_statusline(len);
+ }
+
+ if(s.state == WEBCLIENT_STATE_HEADERS && len > 0) {
+ len = parse_headers(len);
+ }
+
+ if(len > 0 && s.state == WEBCLIENT_STATE_DATA &&
+ s.httpflag != HTTPFLAG_MOVED) {
+ webclient_datahandler((char *)uip_appdata, len);
+ }
+}
+/*-----------------------------------------------------------------------------------*/
+void webclient_appcall(void)
+{
+ if(uip_connected()) {
+ s.timer = 0;
+ s.state = WEBCLIENT_STATE_STATUSLINE;
+ senddata();
+ webclient_connected();
+ return;
+ }
+
+ if(s.state == WEBCLIENT_STATE_CLOSE) {
+ webclient_closed();
+ uip_abort();
+ return;
+ }
+
+ if(uip_aborted()) {
+ webclient_aborted();
+ }
+
+ if(uip_timedout()) {
+ webclient_timedout();
+ }
+
+ if(uip_acked()) {
+ s.timer = 0;
+ acked();
+ }
+
+ if(uip_newdata()) {
+ s.timer = 0;
+ newdata();
+ }
+
+ if(uip_rexmit() || uip_newdata() || uip_acked()) {
+ senddata();
+ }
+ else if(uip_poll()) {
+ ++s.timer;
+ if(s.timer == WEBCLIENT_TIMEOUT) {
+ webclient_timedout();
+ uip_abort();
+ return;
+ }
+ }
+
+ if(uip_closed()) {
+ if(s.httpflag != HTTPFLAG_MOVED) {
+ /* Send NULL data to signal EOF. */
+ webclient_datahandler(NULL, 0);
+ }
+ else {
+ //webclient_get(s.host, s.port, s.file);
+ }
+ }
+}
+/*-----------------------------------------------------------------------------------*/
+
+void webclient_datahandler(char *data, u16_t len)
+{
+}
+
+void webclient_connected(void)
+{
+}
+
+void webclient_timedout(void)
+{
+}
+
+void webclient_aborted(void)
+{
+}
+
+void webclient_closed(void)
+{
+}
+
+/** @} */
+/** @} */
diff --git a/Libraries/WiShield/examples/WebServer/WebServer.pde b/Libraries/WiShield/examples/WebServer/WebServer.pde
new file mode 100644
index 0000000..d0d23b9
--- /dev/null
+++ b/Libraries/WiShield/examples/WebServer/WebServer.pde
@@ -0,0 +1,51 @@
+/*
+ * Web Server
+ *
+ * A simple web server example using the WiShield 1.0
+ */
+
+#include <WiShield.h>
+
+#define WIRELESS_MODE_INFRA 1
+#define WIRELESS_MODE_ADHOC 2
+
+// Wireless configuration parameters ----------------------------------------
+unsigned char local_ip[] = {192,168,1,2}; // IP address of WiShield
+unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
+unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
+const prog_char ssid[] PROGMEM = {"ASYNCLABS"}; // max 32 bytes
+
+unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
+
+// WPA/WPA2 passphrase
+const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters
+
+// WEP 128-bit keys
+// sample HEX keys
+prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
+ };
+
+// setup the wireless mode
+// infrastructure - connect to AP
+// adhoc - connect to another WiFi device
+unsigned char wireless_mode = WIRELESS_MODE_INFRA;
+
+unsigned char ssid_len;
+unsigned char security_passphrase_len;
+//---------------------------------------------------------------------------
+
+void setup()
+{
+ WiFi.init();
+}
+
+// This is the webpage that is served up by the webserver
+const prog_char webpage[] PROGMEM = {"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<center><h1>Hello World!! I am WiShield</h1><form method=\"get\" action=\"0\">Toggle LED:<input type=\"submit\" name=\"0\" value=\"LED1\"></input></form></center>"};
+
+void loop()
+{
+ WiFi.run();
+}
diff --git a/Libraries/WiShield/examples/WebServer/webserver.c b/Libraries/WiShield/examples/WebServer/webserver.c
new file mode 100644
index 0000000..68c293e
--- /dev/null
+++ b/Libraries/WiShield/examples/WebServer/webserver.c
@@ -0,0 +1,118 @@
+
+/******************************************************************************
+
+ Filename: webserver.h
+ Description: Webserver app for the WiShield 1.0
+
+ ******************************************************************************
+
+ TCP/IP stack and driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
+ <asynclabs@asynclabs.com>
+
+ Author Date Comment
+ ---------------------------------------------------------------
+ AsyncLabs 05/29/2009 Initial version
+
+ *****************************************************************************/
+
+#include "uip.h"
+#include <string.h>
+#include "webserver.h"
+#include "config.h"
+
+static int handle_connection(struct webserver_state *s);
+
+void webserver_init(void)
+{
+ uip_listen(HTONS(80));
+}
+
+void webserver_appcall(void)
+{
+ struct webserver_state *s = &(uip_conn->appstate);
+
+ if(uip_connected()) {
+ PSOCK_INIT(&s->p, s->inputbuf, sizeof(s->inputbuf));
+ }
+
+ handle_connection(s);
+}
+
+#define ISO_nl 0x0a
+#define ISO_space 0x20
+#define ISO_slash 0x2f
+
+const char http_get[5] = {0x47, 0x45, 0x54, 0x20, }; /* "GET " */
+
+unsigned short fill_buf(void* blk)
+{
+ unsigned short webpage_len;
+
+ webpage_len = (strlen_P(webpage)>uip_mss())?uip_mss():strlen_P(webpage);
+
+ memcpy_P(uip_appdata, webpage, webpage_len);
+ return webpage_len;
+}
+
+static int handle_connection(struct webserver_state *s)
+{
+ PSOCK_BEGIN(&s->p);
+
+ // the incoming GET request will have the following format:
+ // GET / HTTP/1.1 ....
+ // we have to parse this string to determine the resource being requested
+ // if the requested resource is not the root webpage ('/') then,
+ // GET /<resource name> HTTP/1.1 ....
+ // we should parse the specific resource and react appropriately
+
+ // read incoming data until we read a space character
+ PSOCK_READTO(&s->p, ISO_space);
+
+ // parse the data to determine if it was a GET request
+ if(strncmp(s->inputbuf, http_get, 4) != 0) {
+ PSOCK_CLOSE_EXIT(&s->p);
+ }
+
+ // continue reading until the next space character
+ PSOCK_READTO(&s->p, ISO_space);
+
+ // determine the requested resource
+ // in this case, we check if the request was for the '/' root page
+ // AKA index.html
+ if(s->inputbuf[0] != ISO_slash) {
+ // request for unknown webpage, close and exit
+ PSOCK_CLOSE_EXIT(&s->p);
+ }
+
+ if(s->inputbuf[1] != ISO_space) {
+ // request for unavailable resource
+ // not supported, modify to add support for additional resources
+ PSOCK_CLOSE_EXIT(&s->p);
+ }
+
+ //PSOCK_SEND_STR(&s->p, "HTTP/1.1 200 OK\r\n");
+ //PSOCK_SEND_STR(&s->p, "Content-Type: text/html\r\n");
+ //PSOCK_SEND_STR(&s->p, "\r\n");
+ //PSOCK_SEND_STR(&s->p, "Hello World, I am WiShield");
+ //PSOCK_SEND_STR(&s->p, "<center><h1>Hello World!! I am WiShield</h1></center>");
+ PSOCK_GENERATOR_SEND(&s->p, fill_buf, 0);
+ PSOCK_CLOSE(&s->p);
+ PSOCK_END(&s->p);
+}