Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetNetIf mbed HTTPServer
HTTPServerExample.cpp
00001 #include "mbed.h" 00002 #include "EthernetNetIf.h" 00003 #include "HTTPServer.h" 00004 00005 DigitalOut led1(LED1, "led1"); 00006 DigitalOut led2(LED2, "led2"); 00007 DigitalOut led3(LED3, "led3"); 00008 DigitalOut led4(LED4, "led4"); 00009 00010 LocalFileSystem fs("webfs"); 00011 00012 EthernetNetIf eth; 00013 /*EthernetNetIf eth( 00014 IpAddr(192,168,0,111), //IP Address 00015 IpAddr(255,255,255,0), //Network Mask 00016 IpAddr(192,168,0,1), //Gateway 00017 IpAddr(192,168,0,1) //DNS 00018 );*/ 00019 HTTPServer svr; 00020 00021 int main() { 00022 Base::add_rpc_class<DigitalOut>(); 00023 00024 printf("Setting up...\n"); 00025 EthernetErr ethErr = eth.setup(); 00026 if(ethErr) 00027 { 00028 printf("Error %d in setup.\n", ethErr); 00029 return -1; 00030 } 00031 printf("Setup OK\n"); 00032 00033 FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path 00034 FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path 00035 00036 svr.addHandler<SimpleHandler>("/hello"); 00037 svr.addHandler<RPCHandler>("/rpc"); 00038 svr.addHandler<FSHandler>("/files"); 00039 svr.addHandler<FSHandler>("/"); //Default handler 00040 //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm 00041 00042 svr.bind(80); 00043 00044 printf("Listening...\n"); 00045 00046 Timer tm; 00047 tm.start(); 00048 //Listen indefinitely 00049 while(true) 00050 { 00051 Net::poll(); 00052 if(tm.read()>.5) 00053 { 00054 led1=!led1; //Show that we are alive 00055 tm.start(); 00056 } 00057 } 00058 00059 return 0; 00060 00061 }
Generated on Sun Jul 24 2022 19:36:28 by
1.7.2