SimpleSocket 1.0 examples
Dependencies: EthernetNetIf SimpleSocket 1.0 mbed
Diff: webserver.cpp
- Revision:
- 39:108499af2b53
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/webserver.cpp Wed Jun 06 03:34:16 2012 +0000 @@ -0,0 +1,51 @@ +#include "EthernetNetIf.h" +#include "SimpleSocket.h" + +void webserver() { + const char *response0 = + "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html\r\n" + "\r\n" + "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5\">\r\n" + "<html>\r\n" + "<head>\r\n" + "<title>mbed web server</title>\r\n" + "</head>\r\n" + "<body>\r\n" + "<h2>Analog Input</h2>\r\n" + "<table cellpadding=\"5\">\r\n"; + const char *response1 = + "<tr style=\"background:#ccccff\">" + "<th>pin</th><th>value</th>" + "</tr>\r\n"; + const char *response2 = + "<tr style=\"background:#cccccc\">" + "<td>p%d</td><td align=\"center\">%f</td>" + "</tr>\r\n"; + const char *response3 = + "</table>\r\n" + "</body>\r\n" + "</html>\r\n"; + + EthernetNetIf eth; + eth.setup(); + + ServerSocket server(80); + + while (true) { + ClientSocket socket = server.accept(); + while (socket) { + if (socket.available()) { + while (socket.available()) + socket.read(); + socket.printf(response0); + socket.printf(response1); + AnalogIn analogPin[] = {p15, p16, p17, p18, p19, p20}; + for (int i = 0; i < 6; i++) + socket.printf(response2, 15 + i, analogPin[i].read()); + socket.printf(response3); + socket.close(); + } + } + } +} \ No newline at end of file