![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
SimpleSocket 1.0 examples
Dependencies: EthernetNetIf SimpleSocket 1.0 mbed
webserver.cpp@32:00114e36de90, 2011-10-26 (annotated)
- Committer:
- yamaguch
- Date:
- Wed Oct 26 12:47:31 2011 +0000
- Revision:
- 32:00114e36de90
- Child:
- 33:39d9cdf99de8
UDP added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yamaguch |
32:00114e36de90 | 1 | #include "mbed.h" |
yamaguch |
32:00114e36de90 | 2 | #include "SimpleSocket.h" |
yamaguch |
32:00114e36de90 | 3 | // <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5\">\ |
yamaguch |
32:00114e36de90 | 4 | |
yamaguch |
32:00114e36de90 | 5 | char *response0 = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\ |
yamaguch |
32:00114e36de90 | 6 | <html>\r\n<head>\r\n<title>mbed web server</title>\r\n</head>\r\n\ |
yamaguch |
32:00114e36de90 | 7 | <body>\r\n<h2>Analog Input</h2>\r\n\ |
yamaguch |
32:00114e36de90 | 8 | <table cellpadding=\"5\">"; |
yamaguch |
32:00114e36de90 | 9 | char *response1 = "<tr style=\"background:#ccccff\"><th>pin</th><th>value</th></tr>\r\n"; |
yamaguch |
32:00114e36de90 | 10 | char *response2 = "<tr style=\"background:#cccccc\"><td>p%d</td><td align=\"center\">%f</td></tr>\r\n"; |
yamaguch |
32:00114e36de90 | 11 | char *response3 = "</table>\r\n</body>\r\n</html>\r\n"; |
yamaguch |
32:00114e36de90 | 12 | |
yamaguch |
32:00114e36de90 | 13 | void webserver() { |
yamaguch |
32:00114e36de90 | 14 | ServerSocket server(80); |
yamaguch |
32:00114e36de90 | 15 | while (true) { |
yamaguch |
32:00114e36de90 | 16 | ClientSocket socket = server.accept(); |
yamaguch |
32:00114e36de90 | 17 | while (socket) { |
yamaguch |
32:00114e36de90 | 18 | if (socket.available()) { |
yamaguch |
32:00114e36de90 | 19 | while (socket.available()) |
yamaguch |
32:00114e36de90 | 20 | socket.read(); |
yamaguch |
32:00114e36de90 | 21 | socket.printf(response0); |
yamaguch |
32:00114e36de90 | 22 | socket.printf(response1); |
yamaguch |
32:00114e36de90 | 23 | AnalogIn analogPin[] = {p15, p16, p17, p18, p19, p20}; |
yamaguch |
32:00114e36de90 | 24 | for (int i = 0; i < 6; i++) |
yamaguch |
32:00114e36de90 | 25 | socket.printf(response2, 15 + i, analogPin[i].read()); |
yamaguch |
32:00114e36de90 | 26 | socket.printf(response3); |
yamaguch |
32:00114e36de90 | 27 | socket.close(); |
yamaguch |
32:00114e36de90 | 28 | } |
yamaguch |
32:00114e36de90 | 29 | } |
yamaguch |
32:00114e36de90 | 30 | } |
yamaguch |
32:00114e36de90 | 31 | } |