Serveur web embarqué mbed. Il faut placer index.htm et les (éventuels) autres fichiers htm dans le mbed. Pas d'interaction avec Mbed dans ce programme.
Dependencies: EthernetNetIf HTTPServer mbed
Fork of webserver by
main.cpp@0:275cd7ae0902, 2012-06-17 (annotated)
- Committer:
- nobuki
- Date:
- Sun Jun 17 03:53:43 2012 +0000
- Revision:
- 0:275cd7ae0902
- Child:
- 1:f7e79e41ffdc
Version 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nobuki | 0:275cd7ae0902 | 1 | #include "mbed.h" |
nobuki | 0:275cd7ae0902 | 2 | #include "EthernetNetIf.h" |
nobuki | 0:275cd7ae0902 | 3 | #include "HTTPServer.h" |
nobuki | 0:275cd7ae0902 | 4 | |
nobuki | 0:275cd7ae0902 | 5 | EthernetNetIf ethif( IpAddr(192,168,1,102), // IP |
nobuki | 0:275cd7ae0902 | 6 | IpAddr(255,255,255,0), // Subnet mask |
nobuki | 0:275cd7ae0902 | 7 | IpAddr(192,168,1,1), // Gateway |
nobuki | 0:275cd7ae0902 | 8 | IpAddr(192,168,1,1) ); // DNS |
nobuki | 0:275cd7ae0902 | 9 | HTTPServer server; |
nobuki | 0:275cd7ae0902 | 10 | LocalFileSystem local("local"); // Define local file mount point |
nobuki | 0:275cd7ae0902 | 11 | DigitalOut led1(LED1); // for alive check |
nobuki | 0:275cd7ae0902 | 12 | |
nobuki | 0:275cd7ae0902 | 13 | int main(void) |
nobuki | 0:275cd7ae0902 | 14 | { |
nobuki | 0:275cd7ae0902 | 15 | // EthernetNetIf setup |
nobuki | 0:275cd7ae0902 | 16 | if( ethif.setup() ) |
nobuki | 0:275cd7ae0902 | 17 | { |
nobuki | 0:275cd7ae0902 | 18 | return 1; |
nobuki | 0:275cd7ae0902 | 19 | } |
nobuki | 0:275cd7ae0902 | 20 | |
nobuki | 0:275cd7ae0902 | 21 | // Mount local file path on web root path |
nobuki | 0:275cd7ae0902 | 22 | FSHandler::mount("/local", "/"); |
nobuki | 0:275cd7ae0902 | 23 | // Set web root path handler |
nobuki | 0:275cd7ae0902 | 24 | server.addHandler<FSHandler>("/"); |
nobuki | 0:275cd7ae0902 | 25 | |
nobuki | 0:275cd7ae0902 | 26 | // Set http port |
nobuki | 0:275cd7ae0902 | 27 | server.bind(80); |
nobuki | 0:275cd7ae0902 | 28 | |
nobuki | 0:275cd7ae0902 | 29 | Timer tm; |
nobuki | 0:275cd7ae0902 | 30 | tm.start(); |
nobuki | 0:275cd7ae0902 | 31 | while(1) |
nobuki | 0:275cd7ae0902 | 32 | { |
nobuki | 0:275cd7ae0902 | 33 | Net::poll(); |
nobuki | 0:275cd7ae0902 | 34 | if( 1.0 < tm.read() ) |
nobuki | 0:275cd7ae0902 | 35 | { |
nobuki | 0:275cd7ae0902 | 36 | led1 = !led1; // high->low, low->high |
nobuki | 0:275cd7ae0902 | 37 | tm.start(); |
nobuki | 0:275cd7ae0902 | 38 | } |
nobuki | 0:275cd7ae0902 | 39 | } |
nobuki | 0:275cd7ae0902 | 40 | } |