University of Essex CE713

Dependencies:   mbed HTTPServer EthernetNetIf TextLCD

Fork of HTTPServerHelloWorld by Robert Gutknecht

Revision:
5:8b8c719307bf
Parent:
4:7b810308854e
Child:
6:7929de136a42
diff -r 7b810308854e -r 8b8c719307bf main.cpp
--- a/main.cpp	Thu Nov 30 13:43:02 2017 +0000
+++ b/main.cpp	Thu Nov 30 15:13:11 2017 +0000
@@ -46,24 +46,20 @@
 
 int InitWebServer() {
   EthernetErr ethErr = eth.setup();
-  if(ethErr)
-  {
+  if(ethErr) {
     return -1;
   }
   FILE *fp = fopen("/webfs/index.htm", "w");          // Open "out.txt" on the local file system for writing
   fprintf(fp, "<html><head><title>Hello World online</title></head><body><h1>Hello World from Mbed NXP LPC1768!</h1></body></html>");
-  fclose(fp);
-  FSHandler::mount("/webfs", "/files");               //Mount /webfs path on /files web path
-  FSHandler::mount("/webfs", "/");                    //Mount /webfs path on web root path
-  
+  fclose(fp);                                         // Close file
+  FSHandler::mount("/webfs", "/files");               // Mount /webfs path on /files web path
+  FSHandler::mount("/webfs", "/");                    // Mount /webfs path on web root path
   svr.addHandler<SimpleHandler>("/hello");
   svr.addHandler<RPCHandler>("/rpc");
   svr.addHandler<FSHandler>("/files");
-  svr.addHandler<FSHandler>("/");                     //Default handler
-  //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm
-  
-  svr.bind(80);
-  WebUpdate.attach(&WebServerPoll, 0.1);              // update webserver every
+  svr.addHandler<FSHandler>("/");                     // Default handler
+  svr.bind(80);                                       // Example : http://155.245.21.144
+  WebUpdate.attach(&WebServerPoll, 0.1);              // update webserver every 100ms
   return 0;                                           // return without error
 }
 
@@ -73,13 +69,6 @@
   fclose(fp);
 }
 
-void HTTPInt(int v) {
-  char BodyEnd[] = "</h1></body></html>";
-  FILE *fp = fopen("/webfs/index.htm", "w");          // Open "out.txt" on the local file system for writing
-  fprintf(fp, "<html><head><title>Hello World online</title></head><body><h1> %d %s", v, BodyEnd);
-  fclose(fp);
-}
-
 void Servo1(float s) {                                // range +-1
     s=s+1;
     if (s>=0 && s<=2) {
@@ -334,7 +323,9 @@
           spos = -1;                                  // reset servo position
         }                                             //
         Servo1(spos);                                 // update servo
-        HTTPInt(1234);                                // print integer 1234 on web page
-        //HTTPText("<html><head><title>Hello World online</title></head><body><h1>New Message !!!!</h1></body></html>");
+        // HTTPText("<html><head><title>Hello World online</title></head><body><h1>New Message !!!!</h1></body></html>");
+        char Buffer[100];
+        sprintf(Buffer, "<html><head><title>Hello World online</title></head><body><h1> Temperature = %f %s", temp, "</h1></body></html>");
+        HTTPText(Buffer);                             // ouput temperature on web page 
     }
 }