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:

view plain print about
1#include <Ethernet.h>
2
3byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
4byte ip[] = { 10,0,0,20 };
5
6char* content[] = {"<html>",
7"<body>",
8"<h1>Adobe Platform User Group Sydney</h1>",
9"<p>Arduino powered Web Server</p>",
10"<p>How amazing is this?</p>",
11"</body>",
12"</html>"
13};
14
15byte nolines = 7;
16
17// listen on port 80 for connections
18
Server server(80);
19
20void setup()
21{
22 Ethernet.begin(mac, ip);
23 server.begin();
24}
25
26void loop()
27{
28 Client client = server.available();
29
30 if (client) {
31 boolean blankline = false;
32
33 while (client.connected())
34 {
35 if (client.available())
36 {
37 char c = client.read();
38
39 // if line is blank, the http request has ended, so we can send a reply
40
if (c == '\n' && blankline) {
41
42 // Send a standard http response header
43
client.println("HTTP/1.1 200 OK");
44 client.println("Content-Type: text/html");
45 client.println();
46
47 // Send http content
48
for (int i =0; i < nolines; i++) {
49 client.println(content[i]);
50 }
51
52 break;
53 }
54 // we're starting a new line
55
if (c == '\n') {
56 blankline = true;
57 }
58 else if (c != '\r'){
59 blankline = false;
60 }
61 }
62 }
63
64 client.flush();
65 client.stop();
66 }
67}

Related Blog Entries

TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)