Simplest UPnP basic device example. This program to run UPnP basic device on the mbed.

Dependencies:   NyFileSystems libMiMic mbed-rtos mbed

Fork of MbedFileServer by Ryo Iizuka

This is UPnP BasicDevice by MiMicSDK. BasicDevice is most simplest UPnP device.

How To Use

  • Write firmware to your mbed.
  • Reset mbed and update firmware.
  • Check your "network computer" folder by Exproler. (in case of windows.)
  • You can find UPnPBasicDevice hosted by mbed. (If you can not find device then reflesh exploler information.) /media/uploads/nyatla/upnp-exploler.png
  • If you double-click UPnPBasicDevice, the presentation page on device is opened. /media/uploads/nyatla/upnp-presentation.png

Function

  • AutoIP
  • SSDP
  • DeviceDescription hosting (Httpd)
  • SOAP (not implemented)
  • GENA (not implemented)

Source Code

It is simple and short!

/**
 * @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"
#include "SDFileSystem.h"
#include "mimic.h"
#include "utils/PlatformInfo.h"
#include "fsdata.h"
 
 
Net* net;
 
/**
 * Httpd for UPnPService and presentation.
 */
class UPnPBasicDeviceHttpd:public MiMic::Httpd
{
private:
    ModUPnPDevice modupnp;
    ModRomFiles modromfs; //ROM file module    
public:
    UPnPBasicDeviceHttpd(NetConfig& i_cfg):Httpd(i_cfg.getHttpPort())
    {
        //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)
    {
        //try to ModRomFS module. for icon,images.
        if(this->modromfs.execute(i_connection)){
            return;
        }        
        //try to UPnP service. for descriptions.
        if(this->modupnp.execute(i_connection)){
            return;
        }
        //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");     
    }
};
 
NetConfig cfg; //create network configulation
 
int main()
{
    net=new Net();//Net constructor must be created after started RTOS
    //Prepare configulation.
    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
 
    UPnPBasicDeviceHttpd httpd(cfg); //create a httpd instance.
    net->start(cfg);
    httpd.loop();  //start httpd loop.
    return 0;
}

I think that this code helps to make Web connection to your application easily.

Files at this revision

API Documentation at this revision

Comitter:
nyatla
Date:
Mon Oct 27 15:03:05 2014 +0000
Parent:
25:4c9c5e11da67
Child:
27:a7075db6e0e3
Commit message:
update library; fix stack overflow

Changed in this revision

NyFileSystems.lib Show annotated file Show diff for this revision Revisions of this file
NySDFileSystem.lib 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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NyFileSystems.lib	Mon Oct 27 15:03:05 2014 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/nyatla/code/NyFileSystems/#509d2ac0ba4f
--- a/NySDFileSystem.lib	Tue Nov 12 03:53:27 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/nyatla/code/NySDFileSystem/#b2ca0e66c1f7
--- a/libMiMic.lib	Tue Nov 12 03:53:27 2013 +0000
+++ b/libMiMic.lib	Mon Oct 27 15:03:05 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/nyatla/code/libMiMic/#0a24ad966876
+http://mbed.org/users/nyatla/code/libMiMic/#5022828ace54
--- a/main.cpp	Tue Nov 12 03:53:27 2013 +0000
+++ b/main.cpp	Mon Oct 27 15:03:05 2014 +0000
@@ -16,7 +16,6 @@
 #include "fsdata.h"
 
 
-Net* net;
 
 /**
  * Httpd for UPnPService and presentation.
@@ -27,12 +26,12 @@
     ModUPnPDevice modupnp;
     ModRomFiles modromfs; //ROM file module    
 public:
-    UPnPBasicDeviceHttpd(NetConfig& i_cfg):Httpd(i_cfg.getHttpPort())
+    UPnPBasicDeviceHttpd(Net& net,NetConfig& i_cfg):Httpd(i_cfg.getHttpPort())
     {
         //prepare fs data (presentation.html,icon,image.)
         this->modromfs.setParam("rom",FSDATA,3);
         //bind upnp service to module.
-        this->modupnp.setParam(*net);
+        this->modupnp.setParam(net);
     }
     virtual void onRequest(HttpdConnection& i_connection)
     {
@@ -52,11 +51,12 @@
     }
 };
 
-NetConfig cfg; //create network configulation
-
+UPnPBasicDeviceHttpd* httpd;
 int main()
 {
-    net=new Net();//Net constructor must be created after started RTOS
+    NetConfig cfg; //create network configulation
+    Net net;//Net constructor must be created after started RTOS
+
     //Prepare configulation.
     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.
@@ -73,8 +73,8 @@
     */
     
 
-    UPnPBasicDeviceHttpd httpd(cfg); //create a httpd instance.
-    net->start(cfg);
-    httpd.loop();  //start httpd loop.
+    httpd=new UPnPBasicDeviceHttpd(net,cfg); //create a httpd instance.
+    net.start(cfg);
+    httpd->loop();  //start httpd loop.
     return 0;
 }
--- a/mbed-rtos.lib	Tue Nov 12 03:53:27 2013 +0000
+++ b/mbed-rtos.lib	Mon Oct 27 15:03:05 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#ee87e782d34f
+http://mbed.org/users/mbed_official/code/mbed-rtos/#e2da1b20a6d5
--- a/mbed.bld	Tue Nov 12 03:53:27 2013 +0000
+++ b/mbed.bld	Mon Oct 27 15:03:05 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/5e5da4a5990b
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file