Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetNetIf SimpleSocket 1.0 mbed
webserver.cpp
- Committer:
- yamaguch
- Date:
- 2012-06-05
- Revision:
- 36:03c4e6a9a9e9
- Parent:
- 35:3fc65b5d6340
File content as of revision 36:03c4e6a9a9e9:
#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();
}
}
}
}