SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
Creating an Arduino Web
         Server
  From scratch hardware and software
Web Servers

Simpler than you think

A web server

  Listens for connections

  Parses requests

  Send back status messages and resource
  requested
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
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)
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
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
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
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);
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
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
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!
Connection Code

Create a client
Client client = server.available();

Connected
while (client.connected()
{
....
}
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)
HTTP Request Hack


Standard GET request have request followed
by blank line

So just ignore what is requested and check
for blank line
Request Code
Read characters
char c = client.read();

If newline and last character was newline
if (c == 'n' && blankline) {
  ...
}
if (c == 'n') {
      blankline = true;
}
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
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]);
}
Close Connections


Clear up after you
client.flush();
client.stop();
Arduiono Web Server
       Demo


Aruino IDE

Web browser

Weitere ähnliche Inhalte

Was ist angesagt?

Chatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopChatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopyayaria
 
Encrypt all transports
Encrypt all transportsEncrypt all transports
Encrypt all transportsEleanor McHugh
 
Network programming Using Python
Network programming Using PythonNetwork programming Using Python
Network programming Using PythonKarim Sonbol
 
Python Network Programming – Course Applications Guide
Python Network Programming – Course Applications GuidePython Network Programming – Course Applications Guide
Python Network Programming – Course Applications GuideMihai Catalin Teodosiu
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programmingAnung Ariwibowo
 
Socket programming
Socket programmingSocket programming
Socket programmingAnurag Tomar
 
Advanced Sockets Programming
Advanced Sockets ProgrammingAdvanced Sockets Programming
Advanced Sockets Programmingelliando dias
 
maXbox Starter 39 GEO Maps Tutorial
maXbox Starter 39 GEO Maps TutorialmaXbox Starter 39 GEO Maps Tutorial
maXbox Starter 39 GEO Maps TutorialMax Kleiner
 
Hands on with Smart Contracts session #3
Hands on with Smart Contracts session #3Hands on with Smart Contracts session #3
Hands on with Smart Contracts session #3Gene Leybzon
 
[4] 아두이노와 인터넷
[4] 아두이노와 인터넷[4] 아두이노와 인터넷
[4] 아두이노와 인터넷Chiwon Song
 
sbt-ethereum: a terminal for the world computer
sbt-ethereum: a terminal for the world computersbt-ethereum: a terminal for the world computer
sbt-ethereum: a terminal for the world computerSteve Waldman
 
Poker, packets, pipes and Python
Poker, packets, pipes and PythonPoker, packets, pipes and Python
Poker, packets, pipes and PythonRoger Barnes
 
Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programmingelliando dias
 
Opentalk at Large - StS 2005
Opentalk at Large - StS 2005Opentalk at Large - StS 2005
Opentalk at Large - StS 2005Martin Kobetic
 

Was ist angesagt? (20)

Chatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopChatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptop
 
Encrypt all transports
Encrypt all transportsEncrypt all transports
Encrypt all transports
 
Network programming Using Python
Network programming Using PythonNetwork programming Using Python
Network programming Using Python
 
Python Network Programming – Course Applications Guide
Python Network Programming – Course Applications GuidePython Network Programming – Course Applications Guide
Python Network Programming – Course Applications Guide
 
Whispered secrets
Whispered secretsWhispered secrets
Whispered secrets
 
Socket System Calls
Socket System CallsSocket System Calls
Socket System Calls
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programming
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Ppt of socket
Ppt of socketPpt of socket
Ppt of socket
 
Advanced Sockets Programming
Advanced Sockets ProgrammingAdvanced Sockets Programming
Advanced Sockets Programming
 
maXbox Starter 39 GEO Maps Tutorial
maXbox Starter 39 GEO Maps TutorialmaXbox Starter 39 GEO Maps Tutorial
maXbox Starter 39 GEO Maps Tutorial
 
Hands on with Smart Contracts session #3
Hands on with Smart Contracts session #3Hands on with Smart Contracts session #3
Hands on with Smart Contracts session #3
 
[4] 아두이노와 인터넷
[4] 아두이노와 인터넷[4] 아두이노와 인터넷
[4] 아두이노와 인터넷
 
sbt-ethereum: a terminal for the world computer
sbt-ethereum: a terminal for the world computersbt-ethereum: a terminal for the world computer
sbt-ethereum: a terminal for the world computer
 
Poker, packets, pipes and Python
Poker, packets, pipes and PythonPoker, packets, pipes and Python
Poker, packets, pipes and Python
 
Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programming
 
Introduction to Rust
Introduction to RustIntroduction to Rust
Introduction to Rust
 
iCloud keychain
iCloud keychainiCloud keychain
iCloud keychain
 
Opentalk at Large - StS 2005
Opentalk at Large - StS 2005Opentalk at Large - StS 2005
Opentalk at Large - StS 2005
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 

Ähnlich wie Create an Arduino Web Server

Unit-4 networking basics in java
Unit-4 networking basics in javaUnit-4 networking basics in java
Unit-4 networking basics in javaAmol Gaikwad
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in JavaTushar B Kute
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 
Lan chat system
Lan chat systemLan chat system
Lan chat systemWipro
 
Your app lives on the network - networking for web developers
Your app lives on the network - networking for web developersYour app lives on the network - networking for web developers
Your app lives on the network - networking for web developersWim Godden
 
Raspberry pi Part 23
Raspberry pi Part 23Raspberry pi Part 23
Raspberry pi Part 23Techvilla
 
Driver Configuration Webinar
Driver Configuration WebinarDriver Configuration Webinar
Driver Configuration WebinarAVEVA
 
Network Prog.ppt
Network Prog.pptNetwork Prog.ppt
Network Prog.pptEloOgardo
 
Networking Java Socket Programming
Networking Java Socket ProgrammingNetworking Java Socket Programming
Networking Java Socket ProgrammingMousmi Pawar
 

Ähnlich wie Create an Arduino Web Server (20)

Unit-4 networking basics in java
Unit-4 networking basics in javaUnit-4 networking basics in java
Unit-4 networking basics in java
 
Unit 8 Java
Unit 8 JavaUnit 8 Java
Unit 8 Java
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Sockets
Sockets Sockets
Sockets
 
6005679.ppt
6005679.ppt6005679.ppt
6005679.ppt
 
Lan chat system
Lan chat systemLan chat system
Lan chat system
 
Your app lives on the network - networking for web developers
Your app lives on the network - networking for web developersYour app lives on the network - networking for web developers
Your app lives on the network - networking for web developers
 
03 sockets
03 sockets03 sockets
03 sockets
 
Raspberry pi Part 23
Raspberry pi Part 23Raspberry pi Part 23
Raspberry pi Part 23
 
java networking
 java networking java networking
java networking
 
Driver Configuration Webinar
Driver Configuration WebinarDriver Configuration Webinar
Driver Configuration Webinar
 
Java 1
Java 1Java 1
Java 1
 
Networking
NetworkingNetworking
Networking
 
Network Prog.ppt
Network Prog.pptNetwork Prog.ppt
Network Prog.ppt
 
Net Programming.ppt
Net Programming.pptNet Programming.ppt
Net Programming.ppt
 
class30.ppt
class30.pptclass30.ppt
class30.ppt
 
Osi model
Osi modelOsi model
Osi model
 
class28.ppt
class28.pptclass28.ppt
class28.ppt
 
Networking Java Socket Programming
Networking Java Socket ProgrammingNetworking Java Socket Programming
Networking Java Socket Programming
 

Mehr von Justin Mclean

A Practical Guide to Connecting Hardware to Flex
A Practical Guide to Connecting Hardware to FlexA Practical Guide to Connecting Hardware to Flex
A Practical Guide to Connecting Hardware to FlexJustin Mclean
 
ColdFusion Security and Risk Management
ColdFusion Security and Risk ManagementColdFusion Security and Risk Management
ColdFusion Security and Risk ManagementJustin Mclean
 
Connecting RIAs and hardware together
Connecting RIAs and hardware togetherConnecting RIAs and hardware together
Connecting RIAs and hardware togetherJustin Mclean
 
ColdFusion Security and Risk Management
ColdFusion Security and Risk ManagementColdFusion Security and Risk Management
ColdFusion Security and Risk ManagementJustin Mclean
 
Connecting hardware to ColdFusion
Connecting hardware to ColdFusionConnecting hardware to ColdFusion
Connecting hardware to ColdFusionJustin Mclean
 
Connecting open source hardware to the web
Connecting open source hardware to the webConnecting open source hardware to the web
Connecting open source hardware to the webJustin Mclean
 
Putting your device in a browser or on the web
Putting your device in a browser or on the webPutting your device in a browser or on the web
Putting your device in a browser or on the webJustin Mclean
 
Connecting hardware up to ColdFusion
Connecting hardware up to ColdFusionConnecting hardware up to ColdFusion
Connecting hardware up to ColdFusionJustin Mclean
 
Connecting Hardware to Flex (360MAX)
Connecting Hardware to Flex (360MAX)Connecting Hardware to Flex (360MAX)
Connecting Hardware to Flex (360MAX)Justin Mclean
 
A practical guide to connecting hardware to Flex
A practical guide to connecting hardware to FlexA practical guide to connecting hardware to Flex
A practical guide to connecting hardware to FlexJustin Mclean
 

Mehr von Justin Mclean (11)

A Practical Guide to Connecting Hardware to Flex
A Practical Guide to Connecting Hardware to FlexA Practical Guide to Connecting Hardware to Flex
A Practical Guide to Connecting Hardware to Flex
 
ColdFusion Security and Risk Management
ColdFusion Security and Risk ManagementColdFusion Security and Risk Management
ColdFusion Security and Risk Management
 
Connecting RIAs and hardware together
Connecting RIAs and hardware togetherConnecting RIAs and hardware together
Connecting RIAs and hardware together
 
ColdFusion Security and Risk Management
ColdFusion Security and Risk ManagementColdFusion Security and Risk Management
ColdFusion Security and Risk Management
 
Connecting hardware to ColdFusion
Connecting hardware to ColdFusionConnecting hardware to ColdFusion
Connecting hardware to ColdFusion
 
Connecting open source hardware to the web
Connecting open source hardware to the webConnecting open source hardware to the web
Connecting open source hardware to the web
 
Putting your device in a browser or on the web
Putting your device in a browser or on the webPutting your device in a browser or on the web
Putting your device in a browser or on the web
 
Connecting hardware up to ColdFusion
Connecting hardware up to ColdFusionConnecting hardware up to ColdFusion
Connecting hardware up to ColdFusion
 
Edge Of The Web
Edge Of The WebEdge Of The Web
Edge Of The Web
 
Connecting Hardware to Flex (360MAX)
Connecting Hardware to Flex (360MAX)Connecting Hardware to Flex (360MAX)
Connecting Hardware to Flex (360MAX)
 
A practical guide to connecting hardware to Flex
A practical guide to connecting hardware to FlexA practical guide to connecting hardware to Flex
A practical guide to connecting hardware to Flex
 

Kürzlich hochgeladen

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 

Create an Arduino Web Server

  • 1. Creating an Arduino Web Server From scratch hardware and software
  • 2. Web Servers Simpler than you think A web server Listens for connections Parses requests Send back status messages and resource requested
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. Connection Code Create a client Client client = server.available(); Connected while (client.connected() { .... }
  • 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. HTTP Request Hack Standard GET request have request followed by blank line So just ignore what is requested and check for blank line
  • 15. Request Code Read characters char c = client.read(); If newline and last character was newline if (c == 'n' && blankline) { ... } if (c == 'n') { blankline = true; }
  • 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. 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. Close Connections Clear up after you client.flush(); client.stop();
  • 19. Arduiono Web Server Demo Aruino IDE Web browser