Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

New dataflash example.

  • Loading branch information...
commit 5659c27975a4237960b78bb172050bcbb0cb387c 1 parent d92a52f
gsxrex authored
Showing with 214 additions and 0 deletions.
  1. +89 −0 examples/Flash/Flash.pde
  2. +125 −0 examples/Flash/webserver.c
View
89 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();
+}
+
View
125 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);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.