Version 8, working version with Alix, sams and ollies code. Displays time, date and sensor info onto terminal, LCD and networking, and saves onto SD card.

Dependencies:   BMP280 ELEC350-Practicals-FZ429 TextLCD BME280 ntp-client

Revision:
10:eea19f8e6122
Parent:
9:f5eae5211225
Child:
11:42b0c567cc8c
--- a/Network.hpp	Fri Dec 07 13:24:50 2018 +0000
+++ b/Network.hpp	Thu Dec 13 15:24:22 2018 +0000
@@ -14,6 +14,8 @@
 
 //#include "messageStruct.hpp" 
 
+//#include "LCD.hpp"
+
 #include "TCPSocket.h" 
 
 #include <iostream> 
@@ -29,55 +31,55 @@
 
 #define HTTP_HEADER_FIELDS "Content-Type: text/html; charset=utf-8" 
 
-#define HTTP_MESSAGE_BODY1 ""                                    \ 
-"<html>" "\r\n"                                                  \ 
-"  <body style=\"display:flex;text-align:center\">" "\r\n"       \ 
-"    <div style=\"margin:auto\">" "\r\n"                         \ 
-"      <h1>Alright sunshine</h1>" "\r\n"                              \ 
+#define HTTP_MESSAGE_BODY1 ""                                    \
+"<html>" "\r\n"                                                  \
+"  <body style=\"display:flex;text-align:center\">" "\r\n"       \
+"    <div style=\"margin:auto\">" "\r\n"                         \
+"      <h1>Alright sunshine</h1>" "\r\n"                         \
 "      <p>The LDR value is "                                    
 
-#define HTTP_MESSAGE_BODY2 ""                                    \ 
-       "</p>" "\r\n"                                             \ 
-"    </div>" "\r\n"                                              \ 
-"  </body>" "\r\n"                                               \ 
+#define HTTP_MESSAGE_BODY2 ""                                    \
+       "</p>" "\r\n"                                             \
+"    </div>" "\r\n"                                              \
+"  </body>" "\r\n"                                               \
 "</html>" 
 
-#define HTTP_MESSAGE_BODY3 ""                                    \ 
-"<html>" "\r\n"                                                  \ 
-"  <body style=\"display:flex;text-align:center\">" "\r\n"       \ 
-"    <div style=\"margin:auto\">" "\r\n"                         \ 
-"      <p>The Temperature value is "     
+#define HTTP_MESSAGE_BODY3 ""                                    \
+"<html>" "\r\n"                                                  \
+"  <body style=\"display:flex;text-align:center\">" "\r\n"       \
+"    <div style=\"margin:auto\">" "\r\n"                         \
+"      <p>The Temperature value is "
 
-#define HTTP_MESSAGE_BODY4 ""                                    \ 
-       "</p>" "\r\n"                                             \ 
-"    </div>" "\r\n"                                              \ 
-"  </body>" "\r\n"                                               \ 
-"</html>" 
+#define HTTP_MESSAGE_BODY4 ""                                    \
+       "</p>" "\r\n"                                             \
+"    </div>" "\r\n"                                              \
+"  </body>" "\r\n"                                               \
+"</html>"
 
-#define HTTP_MESSAGE_BODY5 ""                                    \ 
-"<html>" "\r\n"                                                  \ 
-"  <body style=\"display:flex;text-align:center\">" "\r\n"       \ 
-"    <div style=\"margin:auto\">" "\r\n"                         \ 
-"      <p>The Pressure value is "       
+#define HTTP_MESSAGE_BODY5 ""                                    \
+"<html>" "\r\n"                                                  \
+"  <body style=\"display:flex;text-align:center\">" "\r\n"       \
+"    <div style=\"margin:auto\">" "\r\n"                         \
+"      <p>The Pressure value is "
 
-#define HTTP_MESSAGE_BODY6 ""                                    \ 
-       "</p>" "\r\n"                                             \ 
-"    </div>" "\r\n"                                              \ 
-"  </body>" "\r\n"                                               \ 
-"</html>" 
+#define HTTP_MESSAGE_BODY6 ""                                    \
+       "</p>" "\r\n"                                             \
+"    </div>" "\r\n"                                              \
+"  </body>" "\r\n"                                               \
+"</html>"
 
-#define HTTP_RESPONSE HTTP_STATUS_LINE "\r\n"   \ 
-                      HTTP_HEADER_FIELDS "\r\n" \ 
-                      "\r\n"                    \ 
-                      HTTP_MESSAGE_BODY "\r\n" 
+#define HTTP_RESPONSE HTTP_STATUS_LINE "\r\n"   \
+                      HTTP_HEADER_FIELDS "\r\n" \
+                      "\r\n"                    \
+                      HTTP_MESSAGE_BODY "\r\n"
 
   
 
-#define IP        "10.0.0.10" 
+#define IP        "10.0.0.10"
 
-#define NETMASK   "255.0.0.0" 
+#define NETMASK   "255.0.0.0"
 
-#define GATEWAY   "10.0.0.2" 
+#define GATEWAY   "10.0.0.2"
 
 EthernetInterface eth; 
 
@@ -87,58 +89,33 @@
   
 
 class Network 
-
 { 
-
+//friend class LCD_Data;
     private: 
-
-     
-
      float temp;       //current temperature of sensor 
-
      float pressure;  //current pressure of sensor 
-
      float fLDR;      //current light level from LDR 
-
-      
+     string time;
 
       void update_temp(double t) //use this function to update the current temperature value 
-
             { 
-
                 temp = 5; 
-
             }  
 
         void update_pressure(double p) //use this function to update the current pressure value 
-
             { 
-
                 pressure = 4;     
-
             }  
 
         void update_LDR(double L) 
-
             { 
-
                 fLDR = 3;    
-
             } 
 
              
-
-     
-
     public: 
-
     EventQueue Network_Queue; 
 
-    //EthernetInterface eth; 
-
-    //NTPClient ntp(&eth);   
-
-
 
 
     Network(){     //constructor  
@@ -148,15 +125,10 @@
     eth.connect(); 
            
     } 
-
-  
-
   
 
     ~Network(){     //deconstructor  
 
-  
-
     } 
 
   
@@ -166,17 +138,16 @@
       void update_sensor_info(sample_message msg) //updates all current sensor information, this is called by a ticker every 5 seconds to read from the mailbox 
 
     { 
-
          update_temp(msg.temp);                  // Include message class passing of data 
-
          update_pressure(msg.pressure); 
-
          update_LDR(msg.ldr); 
-
     } 
 
      
-
+    void update_Time(string tm)
+    {
+        time = tm;
+    }
      
 
     void NetPush(){ 
@@ -185,33 +156,23 @@
   //Now setup a web server 
 
     TCPServer srv;           //TCP/IP Server 
-
     TCPSocket clt_sock;      //Socket for communication 
-
     SocketAddress clt_addr;  //Address of incoming connection 
 
-     
 
      
 
     /* 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); 
 
-     
-
       //Block and wait on an incoming connection 
 
         srv.accept(&clt_sock, &clt_addr); 
@@ -270,8 +231,11 @@
 
          response += HTTP_MESSAGE_BODY5; 
 
-        response += pressure_str; 
+        //response += pressure_str; 
 
+        response += time; 
+        
+        
         response += HTTP_MESSAGE_BODY6;