PROJ515 / Mbed OS ELEC-351-GROUP-E-CW

Dependencies:   BMP280

Files at this revision

API Documentation at this revision

Comitter:
mwthewsey
Date:
Tue Jan 09 10:25:17 2018 +0000
Parent:
12:03589f1d5c30
Child:
19:40c721f01ed2
Commit message:
Serial,LCD,Sampling,SD,Web Working.

Changed in this revision

SDCard.cpp Show annotated file Show diff for this revision Revisions of this file
Serial.cpp Show annotated file Show diff for this revision Revisions of this file
WebUI.cpp Show annotated file Show diff for this revision Revisions of this file
WebUI.h 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
--- a/SDCard.cpp	Tue Jan 09 08:57:57 2018 +0000
+++ b/SDCard.cpp	Tue Jan 09 10:25:17 2018 +0000
@@ -113,7 +113,8 @@
             Sampling(false);         //Stop sampling
             SDinternalIndex = currentIndex; //InternalIndex for incrementing out data
             TakeKeys(true); //Take keys
-
+            
+            fprintf(fp,"Date,Time,Temperature,Pressure,Light\n");
             for (short i = 0; i < BUFFERSIZE; i++) { //For loop of length buffersize
                 tm T = ReturnDateTimeStruct(timeReadings[SDinternalIndex]);
                 //InternalIndex was set as newest. We will now decrement to display oldest to newest
--- a/Serial.cpp	Tue Jan 09 08:57:57 2018 +0000
+++ b/Serial.cpp	Tue Jan 09 10:25:17 2018 +0000
@@ -28,7 +28,7 @@
 void RXInterruptISR(void)
 {
     SerialThread.signal_set(1);     //Set thread signal to start SerialCode
-    PC.attach(NULL, Serial::RxIrq); //Disable interrupt
+    PC.attach(NULL); //Disable interrupt
 }
 
 
@@ -98,7 +98,7 @@
         } else if (InputBufferString == "read") {
 
             PC.printf("How many records would you like to view:\n\r");
-            PC.attach(&RXInterruptISR, Serial::RxIrq); //Enable interrupt
+            PC.attach(&RXInterruptISR); //Enable interrupt
             Thread::signal_wait(1);      //Wait untill signal set
 
             PC.scanf("%d", &InputBufferNum); //Scan serial
@@ -123,7 +123,7 @@
         } else if (InputBufferString == "delete") {
 
             PC.printf("How many records would you like to delete:\n\r");
-            PC.attach(&RXInterruptISR, Serial::RxIrq); //Enable interrupt
+            PC.attach(&RXInterruptISR); //Enable interrupt
             Thread::signal_wait(1);      //Wait untill signal set
 
             PC.scanf("%d", &InputBufferNum); //Scan serial
@@ -158,7 +158,7 @@
                     PC.printf("Input Date <DD>:\n\r");
                 }
 
-                PC.attach(&RXInterruptISR, Serial::RxIrq); //Enable interrupt
+                PC.attach(&RXInterruptISR); //Enable interrupt
                 Thread::signal_wait(1);      //Wait untill signal set
 
                 PC.scanf("%d", &DateTimeVar[i]); //Scan serial
@@ -183,7 +183,7 @@
                     PC.printf("Input Seccond <ss>:\n\r");
                 }
 
-                PC.attach(&RXInterruptISR, Serial::RxIrq); //Enable interrupt
+                PC.attach(&RXInterruptISR); //Enable interrupt
                 Thread::signal_wait(1);      //Wait untill signal set
 
                 PC.scanf("%d", &DateTimeVar[i]); //Scan serial
@@ -211,6 +211,6 @@
         }
 
 
-        PC.attach(&RXInterruptISR, Serial::RxIrq); //Enable interrupt
+        PC.attach(&RXInterruptISR); //Enable interrupt
     }
 }
\ No newline at end of file
--- a/WebUI.cpp	Tue Jan 09 08:57:57 2018 +0000
+++ b/WebUI.cpp	Tue Jan 09 10:25:17 2018 +0000
@@ -1,28 +1,28 @@
 #if !FEATURE_LWIP
-    #error [NOT_SUPPORTED] LWIP not supported for this target
+#error [NOT_SUPPORTED] LWIP not supported for this target
 #endif
 //We need to look into what if statements like the one above do.
 #include "WebUI.h"
 #include "mbed.h"
-#include "EthernetInterface.h"
-#include "TCPServer.h"
-#include "TCPSocket.h"
-#include <iostream>
-#include <string> 
+#include "Sampling.h"
 
+Thread WebThread;
 //Now setup a web server
 TCPServer srv;           //TCP/IP Server
 TCPSocket clt_sock;      //Socket for communication
 SocketAddress clt_addr;  //Address of incoming connection
+EthernetInterface eth;
+using namespace std;
 
 #define HTTP_STATUS_LINE "HTTP/1.0 200 OK"
 #define HTTP_HEADER_FIELDS "Content-Type: text/html; charset=utf-8"
 #define HTTP_MESSAGE_BODY1 ""                                    \
 "<html>" "\r\n"                                                  \
+"<title>Enviromental Readings</title>"               \
 "  <body style=\"display:flex;text-align:center\">" "\r\n"       \
 "    <div style=\"margin:auto\">" "\r\n"                         \
-"      <h1>Hello World</h1>" "\r\n"                              \
-"      <p>The LDR value is "                                     
+"      <h1>Most Recent Readings:</h1>" "\r\n"                    \
+"      <p><b>Time Taken:</b> "
 
 #define HTTP_MESSAGE_BODY2 ""                                    \
        "</p>" "\r\n"                                             \
@@ -39,53 +39,64 @@
 #define NETMASK   "255.0.0.0"
 #define GATEWAY   "10.0.0.1"
 
-void WebUISetup(void){
-    printf("Basic HTTP server example\n");
-    
+void WebUISetup(void)
+{
+    //printf("Basic HTTP server example\n\r");
+
     //Configure an ethernet connection
-    EthernetInterface eth;
+
     eth.set_network(IP, NETMASK, GATEWAY);
     eth.connect();
-    printf("The target IP address is '%s'\n", eth.get_ip_address());
-    
-    
-    
+    //printf("The target IP address is '%s'\n\r", eth.get_ip_address());
+
+
+
     /* Open the server on ethernet stack */
     srv.open(&eth);
-    
+
     /* Bind the HTTP port (TCP 80) to the server */
     srv.bind(eth.get_ip_address(), 80);
-    
+
     /* Can handle 5 simultaneous connections */
     srv.listen(5);
+    WebThread.start(&WebUIUpdate);
 }
 
-void WebUIUpdate(float ldr){
+void WebUIUpdate(void)
+{
     while (true) {
-        using namespace std;
         //Block and wait on an incoming connection
         srv.accept(&clt_sock, &clt_addr);
-        printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port());
-        
-        //Uses a C++ string to make it easier to concatinate
+
+        //Show that an event has been recieved.
+        //printf("accept %s:%d\n\r", clt_addr.get_ip_address(), clt_addr.get_port());
+
+        //This string will hold the HTML that will be sent to the browser
         string response;
-        //This is a C string
+        //This will be a concatenation of several lines for each reading
+        char time_str[64];
+        char temp_str[64];
+        char pres_str[64];
         char ldr_str[64];
-        
-        //Read the LDR value
-        float u = ldr;
-        
-        //Convert to a C String
-        sprintf(ldr_str, "%5.3f", u );
-        printf("LDR: %5.3f\n\r", u);
-        
+
+        tm T = ReturnDateTimeStruct(timeReadings[currentIndex]);   //Convert time int to structure
+
+        //Fill each string with values
+        sprintf(time_str,"%4d/%2d/%2d %2d:%2d:%2d</p>\r\n",T.tm_year,T.tm_mon,T.tm_mday,T.tm_hour,T.tm_min,T.tm_sec);
+        sprintf(temp_str,"<p><b>Temperature:</b> %5.1f C </p>\r\n", tempReadings[currentIndex]);
+        sprintf(pres_str,"<p><b>Pressure:</b> %5.3f mBar </p>\r\n",presReadings[currentIndex]);
+        sprintf(ldr_str, "<p><b>LDR:</b> %5.3f </p>\r\n", LDRReadings[currentIndex]);
+
+
         //Build the C++ string response
         response = HTTP_MESSAGE_BODY1;
+        response += time_str;
+        response += temp_str;
+        response += pres_str;
         response += ldr_str;
         response += HTTP_MESSAGE_BODY2;
-        
+
         //Send static HTML response (as a C string)
-        clt_sock.send(response.c_str(), response.size()+6);    
+        clt_sock.send(response.c_str(), response.size()+6);
     }
 }
-    
\ No newline at end of file
--- a/WebUI.h	Tue Jan 09 08:57:57 2018 +0000
+++ b/WebUI.h	Tue Jan 09 10:25:17 2018 +0000
@@ -1,19 +1,32 @@
 #ifndef __WebUI__
 #define __WebUI__
 
+/*
+* This module handles the web interface. WebUISetup() is used to configure the
+* devices.
+* WebUIUpdate() must then be attached to a thread.
+* This will wait on receiving a connection, before grabbing the latest samples
+* and making these part of the HTML response.
+*/
 #include <string>
 #include "EthernetInterface.h"
 #include "TCPServer.h"
 #include "TCPSocket.h"
+#include "TimeInterface.h"
 #include <iostream> 
 
+extern Thread WebThread;
 //Now setup a web server
 extern TCPServer srv;           //TCP/IP Server
 extern TCPSocket clt_sock;      //Socket for communication
 extern SocketAddress clt_addr;  //Address of incoming connection
+extern float LDRVal;  ///are these needed?!?!?!?!?!
+extern float TempVal;
+extern float Pressure;
+extern time_t theTime;
 
 void WebUISetup(void);  //Configures the TCP server
 
-void WebUIUpdate(float ldr); //Might be called as a string, but does have blocking currently.
+void WebUIUpdate(void); //Might be called as a string, but does have blocking currently.
 
 #endif
\ No newline at end of file
--- a/main.cpp	Tue Jan 09 08:57:57 2018 +0000
+++ b/main.cpp	Tue Jan 09 10:25:17 2018 +0000
@@ -32,6 +32,7 @@
     SerialStart();
     lcd.Start();
     SDCardInit();
+    WebUISetup();
 
     
     ConfigThreadsAndIR();