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.

Changes

RevisionDateWhoCommit message
28:3b83785b9b03 2015-09-15 nyatla update libmimic default tip
27:a7075db6e0e3 2014-10-28 nyatla update libMiMic
26:302df93914df 2014-10-27 nyatla update library; fix stack overflow
25:4c9c5e11da67 2013-11-12 nyatla Update libMiMic
24:c0663a235aeb 2013-10-23 nyatla update libMiMic
23:425d9fc60f63 2013-10-03 nyatla update libMiMic
22:6326ecf3f540 2013-08-10 nyatla update libMiMic
21:7dbe2100b419 2013-08-09 nyatla add issue comment
20:4b0b449ddb12 2013-08-09 nyatla First release; simplest UPnP Basicdevice
19:66d729b94d16 2013-08-09 nyatla update libMiMic; support UPnP function.
18:9e6b9380006c 2013-07-11 nyatla update libMiMic
17:0291701fc90b 2013-07-10 nyatla update libMiMic
16:54850ee77652 2013-07-09 nyatla update libMiMic
15:8388180fba2f 2013-07-09 nyatla update libMiMic
14:60dca0b39490 2013-06-20 nyatla update libMiMic
13:4740a0bc6c0d 2013-06-20 nyatla update libMiMic
12:218b57d9a6d4 2013-06-20 nyatla update libMiMic; support DHCP,autoIP,mDNS
11:9f5f3ee2dc63 2013-05-14 nyatla update libMiMic
10:80c05810f911 2013-05-05 nyatla update libMiMic; Add platform auto detection.; The completely same binary runs on mbed and LPCXpresso1769.;
9:e3de48c39ffd 2013-04-29 nyatla update libMiMic
8:c0a4c2b96eb9 2013-04-29 nyatla update libMiMic; (mistake of previous commitment
7:8ce615c06e5d 2013-04-29 nyatla update LibMiMic
6:20dcb08e1b43 2013-04-29 nyatla Add LED blinking
5:6a2a1644ea2c 2013-04-28 nyatla Add sdcard and local file configulation.
4:0a280ed0a848 2013-04-09 nyatla update comment
3:77431c2bd9cb 2013-04-09 nyatla initial version
2:28fd59d6be76 2013-04-06 nyatla fix comment;
1:17ecb1647b64 2013-04-06 nyatla First commit
0:ec1e45489427 2013-04-06 nyatla backup;