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
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.)
- If you double-click UPnPBasicDevice, the presentation page on device is opened.
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.
Diff: main.cpp
- Revision:
- 5:6a2a1644ea2c
- Parent:
- 4:0a280ed0a848
- Child:
- 6:20dcb08e1b43
diff -r 0a280ed0a848 -r 6a2a1644ea2c main.cpp --- 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; }