Making an Arduino Web Server at Adobe Platform User Group
On Monday night at the Adobe Platform User Group we had several short presentations of 6 minuted 40 seconds in length consisting of 20 slides of 20 seconds each (known as Pecha Kucha). There was a wide variety of topics covered in the talks including boat building, martian pictures, google wave, PDF security, social networking reliability and I gave a talk on turning an Arduino into a web server in around 20 lines of code which compiled down to 5K.
Here are the slides from my talk.
Here the the web server code:
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10,0,0,20 };
char* content[] = {"<html>",
"<body>",
"<h1>Adobe Platform User Group Sydney</h1>",
"<p>Arduino powered Web Server</p>",
"<p>How amazing is this?</p>",
"</body>",
"</html>"
};
byte nolines = 7;
// listen on port 80 for connections
Server server(80);
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
Client client = server.available();
if (client) {
boolean blankline = false;
while (client.connected())
{
if (client.available())
{
char c = client.read();
// if line is blank, the http request has ended, so we can send a reply
if (c == '\n' && blankline) {
// Send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// Send http content
for (int i =0; i < nolines; i++) {
client.println(content[i]);
}
break;
}
// we're starting a new line
if (c == '\n') {
blankline = true;
}
else if (c != '\r'){
blankline = false;
}
}
}
client.flush();
client.stop();
}
}
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10,0,0,20 };
char* content[] = {"<html>",
"<body>",
"<h1>Adobe Platform User Group Sydney</h1>",
"<p>Arduino powered Web Server</p>",
"<p>How amazing is this?</p>",
"</body>",
"</html>"
};
byte nolines = 7;
// listen on port 80 for connections
Server server(80);
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
Client client = server.available();
if (client) {
boolean blankline = false;
while (client.connected())
{
if (client.available())
{
char c = client.read();
// if line is blank, the http request has ended, so we can send a reply
if (c == '\n' && blankline) {
// Send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// Send http content
for (int i =0; i < nolines; i++) {
client.println(content[i]);
}
break;
}
// we're starting a new line
if (c == '\n') {
blankline = true;
}
else if (c != '\r'){
blankline = false;
}
}
}
client.flush();
client.stop();
}
}







There are no comments for this entry.
[Add Comment]