more

Dependencies:   C12832_lcd Http_Wifi_Fileserver ZacsProgram mbed

Fork of HTTPServerHelloWorld by Donatien Garnier

Files at this revision

API Documentation at this revision

Comitter:
wellmon7
Date:
Wed Oct 29 01:42:04 2014 +0000
Parent:
2:bd69e4df7955
Commit message:
Trial 1

Changed in this revision

C12832_lcd.lib Show annotated file Show diff for this revision Revisions of this file
EthernetNetIf.lib Show annotated file Show diff for this revision Revisions of this file
HTTPServer.lib Show annotated file Show diff for this revision Revisions of this file
HTTPServerHelloWorld.cpp Show diff for this revision Revisions of this file
PostHandler.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832_lcd.lib	Wed Oct 29 01:42:04 2014 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/HTTPServer/code/C12832_lcd/#9ba5d9c45c32
--- a/EthernetNetIf.lib	Fri Jul 09 14:46:34 2010 +0000
+++ b/EthernetNetIf.lib	Wed Oct 29 01:42:04 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
+http://mbed.org/users/wellmon7/code/Http_Wifi_Fileserver/#5ff4a18d103e
--- a/HTTPServer.lib	Fri Jul 09 14:46:34 2010 +0000
+++ b/HTTPServer.lib	Wed Oct 29 01:42:04 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/donatien/code/HTTPServer/#d753966e4d97
+http://developer.mbed.org/teams/HTTPServer/code/ZacsProgram/#8570ffb99cba
--- a/HTTPServerHelloWorld.cpp	Fri Jul 09 14:46:34 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-#include "mbed.h"
-#include "EthernetNetIf.h"
-#include "HTTPServer.h"
-
-EthernetNetIf eth;  
-HTTPServer svr;
-
-DigitalOut led1(LED1);
-
-int main() {
-  printf("Setting up...\n");
-  EthernetErr ethErr = eth.setup();
-  if(ethErr)
-  {
-    printf("Error %d in setup.\n", ethErr);
-    return -1;
-  }
-  printf("Setup OK\n");
-  
-  svr.addHandler<SimpleHandler>("/"); //Default handler
-  svr.bind(80);
-  
-  printf("Listening...\n");
-    
-  Timer tm;
-  tm.start();
-  //Listen indefinitely
-  while(true)
-  {
-    Net::poll();
-    if(tm.read()>.5)
-    {
-      led1=!led1; //Show that we are alive
-      tm.start();
-    }
-  }
-  
-  return 0;
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PostHandler.cpp	Wed Oct 29 01:42:04 2014 +0000
@@ -0,0 +1,139 @@
+/* 
+SY202 Final Project
+04 MAR 2014
+
+Created by:
+             MIDN 3/C Villemez
+             MIDN 3/C DaCruz
+             MIDN 3/C Wellmon
+
+Resources:
+            LCDR Hoffmeister
+            MBED Cookbook
+
+*/
+
+#include "PostHandler.h"
+#include "string.h"
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include "C12832_lcd.h"
+#include <stdlib.h>
+
+ 
+char* myData; 
+ 
+PostHandler::PostHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket):HTTPRequestHandler(rootPath, path, pTCPSocket){
+}
+ 
+ 
+PostHandler::~PostHandler(){
+}
+ 
+void PostHandler::doGet(){
+}
+ 
+void PostHandler::doPost()
+{
+    
+    //get post variables
+    string _path = path();
+    string _rootpath = rootPath();
+    int _datalen = dataLen();
+    
+}
+ 
+void PostHandler::doHead(){
+}
+ 
+void PostHandler::onReadable(){
+    
+    C12832_LCD lcd;
+    Serial pcx(USBTX, USBRX);
+    
+    int _datalen = dataLen();       //read POST data length
+    if(_datalen <= 1024){           //makes sure that submitted html data is less than size of the buffer
+        char _read_data[1024] = {};
+        
+        //read POST data
+        readData(_read_data, _datalen);
+        myData = _read_data;
+        
+        pcx.printf("TYPED: %s", myData);
+        
+        writeData(_read_data, strlen(_read_data));    //required to call onReadable section
+        
+        LocalFileSystem local("local");
+    
+        /*******************************INPUT VALIDATION*******************************/   
+        int u = 7;
+        //checks the submission for values that aren't accepted. Denies everything but letters.
+        while(u < strlen(myData)){
+            if(iscntrl(myData[u]) !=0 || ispunct(myData[u])!=0 || isdigit(myData[u])!=0) { 
+                pcx.printf("\nCONTROL VALUES FOUND\n");
+                myData = "xxxxxxxsomeone entered bad code >:{\n";
+            }
+            u++;
+        }
+    
+        /**************************END OF INPUT VALIDATION******************************/
+    
+        //Copies submitted string into another buffer to get rid of 'variablename=' at the beginning
+    
+        char final[1024] = {};
+        int i = 7;
+        int x = 0;
+        while(i < (strlen(myData))) {             
+            final[x] = myData[i];
+            i++;
+            x++;
+        }
+    
+    
+        //If submission =='new', copy data in the file that was appended to (myList.txt) and append it to a new file(log.txt). Delete myList.txt until new submission
+    
+        FILE * listFile;
+        char copyData[] = "new";
+        if(strcmp(copyData, final)== 0){
+            int size = 1;
+            int tsize = 1;
+            FILE * history;
+            listFile = fopen ("/local/myList.txt", "r");
+
+            char * bufRead[tsize];
+
+            history = fopen("/local/log.txt", "a");
+            fprintf(history, "**********DAY MARKER**************\n\n");
+          
+            while (size) {
+                size = fread(bufRead,1,1,listFile);
+                fwrite (bufRead , 1, 1, history);
+            }
+            fprintf(history, "\n\n");
+            fclose(listFile);
+            fclose(history);
+            remove("/local/myList.txt");
+            lcd.cls();
+            lcd.printf("     A New Sheet\n    Has Been Started\n      WAITING...");
+        }
+        else{                                             //Write submitted html data to file myList.txt
+            listFile = fopen("/local/myList.txt", "a");
+            fprintf(listFile, "%s \n", final);
+            fclose(listFile);
+            char * show = strcat(final, " signed TAPs");
+            lcd.cls();
+            lcd.printf("%s\n     WAITING...     ",show);
+        }    
+    }
+}
+ 
+void PostHandler::onWriteable(){  
+
+close();}
+ 
+ 
+void PostHandler::onClose(){
+return;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Oct 29 01:42:04 2014 +0000
@@ -0,0 +1,78 @@
+/* 
+SY202 Final Project
+04 MAR 2014
+
+Created by:
+             MIDN 3/C Villemez
+             MIDN 3/C DaCruz
+             MIDN 3/C Wellmon
+
+Resources:
+            LCDR Hoffmeister
+            MBED Cookbook
+
+*/
+
+
+
+#include "mbed.h"
+#include "EthernetNetIf.h"
+#include "HTTPServer.h"
+#include <stdio.h>
+#include <string.h>
+#include <HTTPRequestHandler.h>
+#include "PostHandler.h"
+#include "C12832_lcd.h"
+
+
+C12832_LCD lcd;
+
+EthernetNetIf eth;  
+HTTPServer svr;
+ 
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+
+LocalFileSystem fs("home.htm");
+
+int main() {
+  EthernetErr ethErr = eth.setup();
+  if(ethErr)
+  {
+    printf("Error %d in setup.\n", ethErr);
+    return -1;
+  }
+  printf("Setup OK\n");
+
+  lcd.printf("DaCruz | Wellmon | Villemez\n");
+  lcd.printf ("Server IP: %d.%d.%d.%d\n", eth.m_ip[0], eth.m_ip[1], eth.m_ip[2], eth.m_ip[3]);
+  printf("Server IP: %d.%d.%d.%d\n", eth.m_ip[0], eth.m_ip[1], eth.m_ip[2], eth.m_ip[3]);
+
+  FSHandler::mount("/home.htm", "/");
+ 
+  svr.addHandler<FSHandler>("/"); //Default handler
+  svr.addHandler<PostHandler>("/list.htm");
+  
+  svr.bind(80);
+  
+  printf("Listening...\n");
+    
+  Timer tm;
+  tm.start();
+
+  //Listen indefinitely
+  while(true)
+  {
+    Net::poll();
+      led1=!led1;
+      led2=!led2;
+      led3=!led3;
+      led4=!led4;
+      
+   }
+  
+  return 0;
+}