SEND

Dependencies:   BMP280 LGLCD2

Fork of 0NicksCoursework_copywithserialtime by Liam Grazier

Revision:
10:098c2fa0a1a6
Parent:
8:582ac4c5a524
diff -r e27b3f34de24 -r 098c2fa0a1a6 Network/network.cpp
--- a/Network/network.cpp	Tue Jan 09 06:14:41 2018 +0000
+++ b/Network/network.cpp	Tue Jan 09 11:33:14 2018 +0000
@@ -1,3 +1,7 @@
+/*   ELEC351 COURSEWORK 2018 
+DESIGNED USING MBED ONLINE COMPILER IMPORTED TO KEIL
+LIAM GRAZIER // DOUG TILLEY // ALEX BARON 
+ */
 #if !FEATURE_LWIP
     #error [NOT_SUPPORTED] LWIP not supported for this target
 #endif
@@ -5,13 +9,13 @@
 #include "EthernetInterface.h"
 #include "TCPServer.h"
 #include "TCPSocket.h"
- char realtime[32];
+char realtime[32]; //char for storing the RTC
 #include <iostream>
 #include <string> 
 #include "BMP280.h"
 #include "components.hpp"
 #include "network.hpp"
-Mutex Net;
+Mutex Net;  //mutex lock for the network.
 #define HTTP_STATUS_LINE "HTTP/1.0 200 OK"
 #define HTTP_HEADER_FIELDS "Content-Type: text/html; charset=utf-8"
 #define HTTP_MESSAGE_BODY1 ""                                    \
@@ -69,80 +73,75 @@
                       "\r\n"                    \
                       HTTP_MESSAGE_BODY "\r\n"
 
-#define IP        "10.0.0.10"
-#define NETMASK   "255.0.0.0"
-#define GATEWAY   "10.0.0.1"
-void dispstralltime(){
+#define IP        "10.0.0.10" //ipaddress
+#define NETMASK   "255.0.0.0" //subnetmask
+#define GATEWAY   "10.0.0.1"  //defaultgateway
+void dispstralltime() //function for getting time from the RTC
+{
     time_t seconds = time(NULL);
-    strftime(realtime, 32, "%c\n\r", localtime(&seconds));
-   }
+    strftime(realtime, 32, "%c\n\r", localtime(&seconds)); //realtime value = yyyy/mm/dd/hh/mm/ss
+}
 void networksend(void)
 {   
     // interrupt routine setup
     Net.lock();
-    printf("Network Enabled\n\r");//n
+    printf("Network Enabled\n\r");//here to show the user in terminal network is initalised 
     //Configure an ethernet connection
     EthernetInterface eth;
     eth.set_network(IP, NETMASK, GATEWAY);
     eth.connect();
-//
     Net.unlock();
     //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);
-    
-    while (true) {
+    srv.listen(5); 
+    while (true) 
+    {
         Net.lock();
         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());
-        
+        //printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port());
         double temp = sensor.getTemperature();
         double pres = sensor.getPressure();
         //Uses a C++ string to make it easier to concatinate
         string response;
-        //This is a C string
+        //Chars for storing the variables
         char adcIn_str[64];
         char pres_str[64];
         char temp_str[64];
-        dispstralltime();              
+        dispstralltime();  //calltime           
         //Read the LDR value
+        //declairing floats for storing data
         float u = adcIn;
         float b = pres;
         float a = temp;
-        
-        //Convert to a C String
+        //Converterting the floats to chars ready for print
         sprintf(adcIn_str, "%5.3f", u );
         sprintf(pres_str, "%4.2f", b);
         sprintf(temp_str, "%3.1f", a);
-        
         //Build the C++ string response
         response += HTTP_TIME;
-        response += realtime;
+        response += realtime; //write time
         response += HTTP_MESSAGE_BODY1;
-        response += adcIn_str;
+        response += adcIn_str; //writeadc
         response += HTTP_Temperature1;
-        response += temp_str;
+        response += temp_str; //writetemp
         response += HTTP_Temperature2;
         response += HTTP_Pressure1;
-        response += pres_str;
+        response += pres_str; //writepressure
         response += HTTP_Pressure2;
         response += HTTP_MESSAGE_TIME;
         response += HTTP_MESSAGE_BODY2;       
         //Send static HTML response (as a C string)
         clt_sock.send(response.c_str(), response.size()+6); 
         Net.unlock();   
-        Thread::signal_wait(SIG_NET);
+        Thread::signal_wait(SIG_NET);//thead signal triggered by ticket in main. 
     }
 }