reef monitor

Dependencies:   mbed-rtos EthernetInterface FatFileSystemCpp MCP23S17 SDFileSystem mbed

Fork of HTTPServerHelloWorld by Donatien Garnier

Files at this revision

API Documentation at this revision

Comitter:
wyunreal
Date:
Sat Feb 01 18:54:20 2014 +0000
Parent:
4:a19825caaf41
Child:
6:b2c4687b421d
Commit message:
Adding a FS handler to the webserver and mounting it to the local file system

Changed in this revision

Model/Application.cpp Show annotated file Show diff for this revision Revisions of this file
Model/Application.h Show annotated file Show diff for this revision Revisions of this file
Services/Network/RestServer.cpp Show annotated file Show diff for this revision Revisions of this file
Services/Network/RestServer.h Show annotated file Show diff for this revision Revisions of this file
--- a/Model/Application.cpp	Sat Feb 01 17:29:15 2014 +0000
+++ b/Model/Application.cpp	Sat Feb 01 18:54:20 2014 +0000
@@ -11,17 +11,27 @@
         loop();
         ethernetService->poll();
         if (ethernetService->isLinkRestored()) {
+            // if ethernet link is restored, application needs to be restarted
             applicationReset();
         }
     }
 }
 
 void Application::setup() {
+    // setup ethernet
     ethernetService = new EthernetService();
     if(!ethernetService->setup()) {
         applicationReset();
     }
+    // set the system time from NTP
     ethernetService->setRtcTime();
+    
+    // starting the file system
+    fileSystem = new LocalFileSystem("local");
+    
+    // start the rest api server
+    restServer = new RestServer(fileSystem);
+    restServer->bind();
 }
 
 void Application::loop() {
--- a/Model/Application.h	Sat Feb 01 17:29:15 2014 +0000
+++ b/Model/Application.h	Sat Feb 01 18:54:20 2014 +0000
@@ -2,10 +2,13 @@
 #define APPLICATION_H
 
 #include "EthernetService.h"
+#include "RestServer.h"
 
 class Application {
     private:
         EthernetService* ethernetService;
+        RestServer* restServer;
+        FileSystemLike* fileSystem;
         
         void setup();
         void loop();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Services/Network/RestServer.cpp	Sat Feb 01 18:54:20 2014 +0000
@@ -0,0 +1,17 @@
+#include "RestServer.h"
+
+RestServer::RestServer(FileSystemLike* aFileSystem) {
+    fileSystem = aFileSystem;
+    webServer = new HTTPServer();
+    webServer->addHandler<SimpleHandler>("/testService");
+    FSHandler::mount("/local", "/");
+    webServer->addHandler<FSHandler>("/");
+}
+
+RestServer::~RestServer() {
+    delete webServer;
+}
+
+void RestServer::bind() {
+    webServer->bind(80);    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Services/Network/RestServer.h	Sat Feb 01 18:54:20 2014 +0000
@@ -0,0 +1,17 @@
+#ifndef REST_SERVER_H
+#define REST_SERVER_H
+
+#include "HTTPServer.h"
+
+class RestServer {
+    private:
+        HTTPServer* webServer;
+        FileSystemLike* fileSystem;
+    public:
+        RestServer(FileSystemLike* aFileSystem);
+        ~RestServer();
+        
+        void bind();
+};
+
+#endif
\ No newline at end of file