MiMicSDK Tcp client socket sample program.
Dependencies: NyFileSystems libMiMic mbed-rtos mbed
Fork of WebSocketSample by
main.cpp
- Committer:
- nyatla
- Date:
- 2013-09-27
- Revision:
- 23:6340bfc0bfe3
- Parent:
- 21:7dbe2100b419
- Child:
- 24:83a1d2bc8709
File content as of revision 23:6340bfc0bfe3:
/** * @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" //local filesystem LocalFileSystem2 lf("local"); NetConfig cfg; //create network configulation Net* net; /** * Httpd for UPnPService and presentation. */ class WebSocketHttpd:public MiMic::Httpd { private: ModLocalFileSystem modlocal; ModWebSocket modwebsocket; ModRomFiles modromfs; //ROM file module public: WebSocketHttpd(NetConfig& i_cfg):Httpd(i_cfg.getHttpPort()) { //prepare fs data (presentation.html,icon,image.) this->modromfs.setParam("rom",FSDATA,3); this->modlocal.setParam("local"); //bind websocket module. this->modwebsocket.setParam("ws"); } virtual void onRequest(HttpdConnection& i_connection) { //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 Websocket service. if(this->modwebsocket.execute(i_connection)){ //send AIN1 value every 10ms. AnalogIn ain(p20); do{ Thread::wait(20); }while(this->modwebsocket.writeF("%d,",(int)(ain*4096))); this->modwebsocket.close(); 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"); } }; int main() { net=new Net();//Net constructor must be created after started RTOS // manual setting cfg.setIpAddr(192,168,128,39); cfg.setNetMask(255,255,255,0); cfg.setGateway(192,168,128,254); WebSocketHttpd httpd(cfg); //create a httpd instance. net->start(cfg); httpd.loop(); //start httpd loop. return 0; }