Web server
Dependencies: EthernetNetIf mbed HTTPServer
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetNetIf.h" 00003 #include "HTTPServer.h" 00004 00005 EthernetNetIf ethif( IpAddr(192,168,1,102), // IP 00006 IpAddr(255,255,255,0), // Subnet mask 00007 IpAddr(192,168,1,1), // Gateway 00008 IpAddr(192,168,1,1) ); // DNS 00009 HTTPServer server; 00010 LocalFileSystem local("local"); // Define local file mount point 00011 DigitalOut led1(LED1); // for alive check 00012 00013 int main(void) 00014 { 00015 // EthernetNetIf setup 00016 if( ethif.setup() ) 00017 { 00018 return 1; 00019 } 00020 00021 // Mount local file path on web root path 00022 FSHandler::mount("/local", "/"); 00023 // Set web root path handler 00024 server.addHandler<FSHandler>("/"); 00025 00026 // Set http port 00027 server.bind(80); 00028 00029 Timer tm; 00030 tm.start(); 00031 while(1) 00032 { 00033 Net::poll(); 00034 if( 1.0 < tm.read() ) 00035 { 00036 led1 = !led1; // high->low, low->high 00037 tm.start(); 00038 } 00039 } 00040 }
Generated on Tue Jul 19 2022 00:34:02 by 1.7.2