Creating an Arduino Web Server from scratch hardware and software


Published on

A short presentation of how to turn an Arduino (open source physical computing platform) into a web server in around 20 lines of code.

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Creating an Arduino Web Server from scratch hardware and software

  1. 1. Creating an Arduino Web Server From scratch hardware and software
  2. 2. Web Servers Simpler than you think A web server Listens for connections Parses requests Send back status messages and resource requested
  3. 3. Arduino Overview Open source physical computing platform Multiple form factors Easy to code (C/C++ like) and use (USB) Low cost Great for prototypes, wearable computers, sensor networks etc
  4. 4. Arduino Hardware ATMega 8 bit microcontroller 32K program memory, 2K SRAM, 1K EEPROM Dual purpose digital inputs and outputs Analog inputs High performance (16 MIPS) Low power (3.3V or 5V)
  5. 5. Arduino IDE/Software Open source Cross platform (Mac, PC and Linux) Alpha but stable Simple to use Includes documentation, help, samples and library for common tasks
  6. 6. Arduino Shields Hardware can be easily extended Shields plug in on top of standard boards Build your own or buy off the shelf (lots available) Stackable, can use more than one
  7. 7. Ethernet Shields Several shields available Two main types DHCP and non DHCP Some configuration required Non DHCP you set IP and MAC address in code
  8. 8. IP and MAC address Set IP address and MAC address in your code Need to be careful with duplicates Set up like so: Ethernet.begin(mac, ip);
  9. 9. Ethernet Library Standard ethernet library Includes Client and Server classes Create server like so: Server server(80); server.begin(); Bare bones web server about 20 lines of code and 5K compiled
  10. 10. HTTP Protocol HyperText Transfer Protocol Used by web servers to transfer web pages to be displayed in your web browser Connection (usually) on port 80
  11. 11. TCP Connections TCP three way connection handshake Client sends SYN with random number (A) Server replies with SYN-ACK containing A+1 and random number (B) Client replies with ACK containing B+1 Luckily ethernet library does this for you!
  12. 12. Connection Code Create a client Client client = server.available(); Connected while (client.connected() { .... }
  13. 13. HTTP Requests Start with request “GET index.html HTTP/1.1” Optional headers “Accept-Language: en” Empty line Optional message body (POST and other requests)
  14. 14. HTTP Request Hack Standard GET request have request followed by blank line So just ignore what is requested and check for blank line
  15. 15. Request Code Read characters char c =; If newline and last character was newline if (c == 'n' && blankline) { ... } if (c == 'n') { blankline = true; }
  16. 16. HTTP Response Send back status line "HTTP/1.1 200 OK" Send back content type "Content-Type: text/ html" Send blank line Send (HTML) content
  17. 17. Response Code Send status and content type client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); Send content for (int i =0; i < nolines; i++) { client.println(content[i]); }
  18. 18. Close Connections Clear up after you client.flush(); client.stop();
  19. 19. Arduiono Web Server Demo Aruino IDE Web browser