sensor web server
Dependencies: EthernetNetIf HTTPServer mbed
main.cpp@0:803d8094260a, 2012-11-18 (annotated)
- Committer:
- nobuki
- Date:
- Sun Nov 18 11:24:12 2012 +0000
- Revision:
- 0:803d8094260a
version1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nobuki | 0:803d8094260a | 1 | #include "mbed.h" |
nobuki | 0:803d8094260a | 2 | #include "EthernetNetIf.h" |
nobuki | 0:803d8094260a | 3 | #include "HTTPServer.h" |
nobuki | 0:803d8094260a | 4 | |
nobuki | 0:803d8094260a | 5 | #include "SensorHandler.h" |
nobuki | 0:803d8094260a | 6 | |
nobuki | 0:803d8094260a | 7 | EthernetNetIf ethif( IpAddr(192,168,1,102), // IP |
nobuki | 0:803d8094260a | 8 | IpAddr(255,255,255,0), // Subnet mask |
nobuki | 0:803d8094260a | 9 | IpAddr(192,168,1,1), // Gateway |
nobuki | 0:803d8094260a | 10 | IpAddr(192,168,1,1) ); // DNS |
nobuki | 0:803d8094260a | 11 | HTTPServer server; |
nobuki | 0:803d8094260a | 12 | DigitalOut led1(LED1); // for alive check |
nobuki | 0:803d8094260a | 13 | |
nobuki | 0:803d8094260a | 14 | int main(void) |
nobuki | 0:803d8094260a | 15 | { |
nobuki | 0:803d8094260a | 16 | // EthernetNetIf setup |
nobuki | 0:803d8094260a | 17 | if( ethif.setup() ) |
nobuki | 0:803d8094260a | 18 | { |
nobuki | 0:803d8094260a | 19 | return 1; |
nobuki | 0:803d8094260a | 20 | } |
nobuki | 0:803d8094260a | 21 | |
nobuki | 0:803d8094260a | 22 | // Set web root path handler |
nobuki | 0:803d8094260a | 23 | server.addHandler<SensorHandler>("/"); |
nobuki | 0:803d8094260a | 24 | |
nobuki | 0:803d8094260a | 25 | // Set http port |
nobuki | 0:803d8094260a | 26 | server.bind(80); |
nobuki | 0:803d8094260a | 27 | |
nobuki | 0:803d8094260a | 28 | Timer tm; |
nobuki | 0:803d8094260a | 29 | tm.start(); |
nobuki | 0:803d8094260a | 30 | while(1) |
nobuki | 0:803d8094260a | 31 | { |
nobuki | 0:803d8094260a | 32 | Net::poll(); |
nobuki | 0:803d8094260a | 33 | if( 1.0 < tm.read() ) |
nobuki | 0:803d8094260a | 34 | { |
nobuki | 0:803d8094260a | 35 | led1 = !led1; // high->low, low->high |
nobuki | 0:803d8094260a | 36 | tm.start(); |
nobuki | 0:803d8094260a | 37 | } |
nobuki | 0:803d8094260a | 38 | } |
nobuki | 0:803d8094260a | 39 | } |