MiMicSDK Websocket module sample program.

Dependencies:   NyFileSystems libMiMic mbed-rtos mbed

Fork of UPnPBasicDevice by Ryo Iizuka

This is Websocket server.

WebSocketのサンプルです。 MiMicSDKのWebsocketはhttpdの1モジュールとして動作するので、ファイルサーバ等と一緒に動かすことが出来ます。

ファームウェアを書き込んだ後にブラウザから "http://192.168.128.39/" にアクセスすると、AIN1のデータをリアルタイムに表示するページが開きます。

Files at this revision

API Documentation at this revision

Comitter:
nyatla
Date:
Sun Apr 28 13:33:36 2013 +0000
Parent:
4:0a280ed0a848
Child:
6:20dcb08e1b43
Commit message:
Add sdcard and local file configulation.

Changed in this revision

NySDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
libMiMic.lib 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NySDFileSystem.lib	Sun Apr 28 13:33:36 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/nyatla/code/NySDFileSystem/#22ce3449b224
--- a/libMiMic.lib	Tue Apr 09 10:48:14 2013 +0000
+++ b/libMiMic.lib	Sun Apr 28 13:33:36 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/nyatla/code/libMiMic/#b9ed86e156dd
+http://mbed.org/users/nyatla/code/libMiMic/#0dae06d012e3
--- a/main.cpp	Tue Apr 09 10:48:14 2013 +0000
+++ b/main.cpp	Sun Apr 28 13:33:36 2013 +0000
@@ -8,6 +8,8 @@
  * 3. You can see <filename> file on browser.
  * </pre>
  */
+#include "mbed.h"
+#include "SDFileSystem.h"
 #include "mimic.h"
 
 
@@ -15,34 +17,53 @@
  * local filesystem support.
  */
 LocalFileSystem lf("local");
+SDFileSystem sd(p5, p6, p7, p8,"sd");
 
 /**
  * MiMic RemoteMCU httpd.<br/>
+ * Number of simultaneous connections:4
  * <p>Service list</p>
  * <pre>
  * /local/ - mbed LocalFileSystem
  * </pre>
  */
-class LfsHttpd:public MiMic::Httpd
+class FsHttpd:public MiMic::Httpd
 {
 private:
-    ModLocalFileSystem modurl; //basic URL parser
+    ModLocalFileSystem modlocal;
+    ModLocalFileSystem modsd;
 public:
-    LfsHttpd():Httpd(80)
+    FsHttpd():Httpd(80)
     {
         //bind local file system path to /local/*
-        modurl.setParam("local");
+        modlocal.setParam("local");
+        modsd.setParam("sd");
     }
     virtual void onRequest(HttpdConnection& i_connection)
     {
-        //call ModUrl module.
-        if(!this->modurl.execute(i_connection)){
-            //send 430
-            i_connection.sendHeader(403,"text/html",NULL);
-            i_connection.sendBodyF("<html><body>403 Forbidden</body></html>");
+        //try to ModLocalFileSystem
+        if(this->modlocal.execute(i_connection)){
+            return;
+        }
+        //try to ModLocalFileSystem(SD)
+        if(this->modsd.execute(i_connection)){
             return;
         }
-        return;
+        //Otherwise, Send simple top index page.
+        i_connection.sendHeader(200,"text/html",NULL);
+        if(i_connection.isMethodType(Http::MT_GET)){
+            i_connection.sendBodyF(
+                "<!DOCTYPE html>"
+                "<html lang=\"ja\">"  
+                "<head></head>"
+                "<body>"
+                "<h1>This is MiMic Server!</h1>"
+                "<hr/>"
+                "<ul>"
+                "<li><a href=\"/local/\">mbed Local Filesystem</a></li>"
+                "<li><a href=\"/sd/\">SDCard</a></li>"
+                "</ul></body>");
+        }
     }
 };
 
@@ -50,7 +71,11 @@
 {
     NetConfig cfg; //create network configulation
     Net net(cfg);  //create a net instance.
-    LfsHttpd httpd; //create a httpd instance.
+    //try to override setting by local file.
+    if(!cfg.loadFromFile("/local/mimic.cfg")){
+        cfg.loadFromFile("/sd/mimic.cfg");
+    }    
+    FsHttpd httpd; //create a httpd instance.
     httpd.loop();  //start httpd loop.
     return 0;
 }