A http client sample program.

Dependencies:   NyFileSystems libMiMic mbed-rtos mbed

Fork of TcpSocketClientSamlpe by Ryo Iizuka

Revision:
20:4b0b449ddb12
Parent:
19:66d729b94d16
Child:
21:7dbe2100b419
--- a/main.cpp	Fri Aug 09 09:06:09 2013 +0000
+++ b/main.cpp	Fri Aug 09 10:45:36 2013 +0000
@@ -1,12 +1,12 @@
 /**
- * @file * This is ModLocalFileSystem sample program.
- *
- * <pre>
- * 1. Compile this program and write to your mbed.
- * 2. Write files for testing to mbed disk.
- * 2. Access via web browser to http://192.168.0.39/local/<filename>
- * 3. You can see <filename> file on browser.
- * </pre>
+ * @file
+ * Simplest UPnP basic device.<br/>
+ * This program is upnp:BasicDeveice:1 template.
+ * 
+ * <p>
+ * After starting program, check "network" by Exproler.
+ * MiMic basic device will be appeared.
+ * </p>
  */
 #include "mbed.h"
 #include "rtos.h"
@@ -15,84 +15,40 @@
 #include "utils/PlatformInfo.h"
 #include "fsdata.h"
 
-DigitalOut mbedled(LED1);
-DigitalOut lpcxled(P0_22);
 
-/**
- * local filesystem support.
- */
-LocalFileSystem2 lf("local");
-SDFileSystem sd(p5, p6, p7, p8,"sd");
 Net* net;
 
-unsigned int p;
 /**
- * MiMic RemoteMCU httpd.<br/>
- * Number of simultaneous connections:4
- * <p>Service list</p>
- * <pre>
- * /local/ - mbed LocalFileSystem
- * </pre>
+ * Httpd for UPnPService and presentation.
  */
-class FsHttpd:public MiMic::Httpd
+class UPnPBasicDeviceHttpd:public MiMic::Httpd
 {
 private:
-    ModLocalFileSystem modlocal;
-    ModLocalFileSystem modsd;
     ModUPnPDevice modupnp;
-    ModRomFiles modromfs; //ROM file module
-    
+    ModRomFiles modromfs; //ROM file module    
 public:
-    FsHttpd(NetConfig& i_cfg):Httpd(i_cfg.getHttpPort())
+    UPnPBasicDeviceHttpd(NetConfig& i_cfg):Httpd(i_cfg.getHttpPort())
     {
-    
-        this->modromfs.setParam("rom",FSDATA,1);
-        //bind local file system path to /local/*
-        modlocal.setParam("local");
-        modsd.setParam("sd",ModLocalFileSystem::FST_SDFATFS);
+        //prepare fs data (presentation.html,icon,image.)
+        this->modromfs.setParam("rom",FSDATA,3);
+        //bind upnp service to module.
         this->modupnp.setParam(*net);
     }
     virtual void onRequest(HttpdConnection& i_connection)
     {
-        p++;
-        switch(PlatformInfo::getPlatformType()){
-        case PlatformInfo::PF_MBED:
-            mbedled = p%2;
-            break;
-        case PlatformInfo::PF_LPCXPRESSO:        
-            lpcxled = p%2;
-            break;
-        }
-        //try to ModRomFS module.
+        //try to ModRomFS module. for icon,images.
         if(this->modromfs.execute(i_connection)){
             return;
         }        
-        //try to ModLocalFileSystem
-        if(this->modlocal.execute(i_connection)){
-            return;
-        }
-        //try to ModLocalFileSystem(SD)
-        if(this->modsd.execute(i_connection)){
-            return;
-        }
+        //try to UPnP service. for descriptions.
         if(this->modupnp.execute(i_connection)){
             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>");
-        }
+        //Otherwise, Send the redirect response to /rom/index.html
+        i_connection.sendHeader(302,
+            "text/html",
+            "Status: 302:Moved Temporarily\r\n"
+            "Location: /rom/index.html\r\n");     
     }
 };
 
@@ -102,16 +58,13 @@
 {
     net=new Net();//Net constructor must be created after started RTOS
     //Prepare configulation.
-    cfg.setUPnPIcon(64,64,8,"image/png","/rom/icon.png");
-    cfg.setUPnPUdn(0xe29f7102,0x4ba2,0x01e0,0);
-    cfg.setFriendlyName("MbedFileServer");
+    cfg.setUPnPIcon(64,64,8,"image/png","/rom/icon.png");//set upnp icon address
+    cfg.setUPnPUdn(0xe29f7103,0x4ba2,0x01e0,0); //set application timebase-uuid time and sequence field.
+    cfg.setFriendlyName("UPnPBasicDevice(LPC176x)"); //set friendly name
+    cfg.setUPnPPresentationURL("/rom/index.html"); //set presentationURL
+    cfg.setZeroconf(true);//AutoIP enable
 
-    //try to override setting by local file.
-    if(!cfg.loadFromFile("/local/mimic.cfg")){
-        Thread::wait(2000);//wait for SD card initialization.
-        cfg.loadFromFile("/sd/mimic.cfg");
-    }
-    FsHttpd httpd(cfg); //create a httpd instance.
+    UPnPBasicDeviceHttpd httpd(cfg); //create a httpd instance.
     net->start(cfg);
     httpd.loop();  //start httpd loop.
     return 0;