arduinoethernetw5100.pdf
TRANSCRIPT
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 1/22
Arduino Ethernet Shield
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 2/22
Arduino Ethernet Shield
Arduino + Ethernet
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 3/22
Twittering plant
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 4/22
Capabilities
! Wiznet W5100 ethernet chip! Client! Server!
TCP! UDP! Four channels
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 5/22
The Ethernet library
! All looks like a serial port
! Ethernet: initialise network!
Client: connect to a port on aserver, then read() and write()! Server: waits for a connectionon a port
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 6/22
Ethernet limitations
! DHCP needs 3rd-party library! No DNS! DIY for high-level protocols
(no HTTP library, etc) - lots ofprint() statements! Library memory footprint
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 7/22Practical 1: on the network
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 8/22
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 9/22Configuration
byte mac[] = { 0xDE,0xAD,0xBE,0xEF,0xFE,0xED };
byte ip[] = { 10, 0, 0, 177 };byte gateway[] = { 10, 0, 0, 1 };byte subnet[] = { 255, 255, 0, 0 };
...
Ethernet.begin(mac,ip,gateway,subnet);
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 10/22Talking HTTP
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 11/22Talking HTTP
$ curl -v http://www.example.com
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 12/22Talking HTTP: the request
$ curl -v http://www.example.com* About to connect() to www.example.com port 80 (#0)* Trying 208.77.188.166... connected* Connected to www.example.com (208.77.188.166) port 80 (#0)
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 13/22Talking HTTP: the request
$ curl -v http://www.example.com* About to connect() to www.example.com port 80 (#0)* Trying 208.77.188.166... connected* Connected to www.example.com (208.77.188.166) port 80 (#0)> GET / HTTP/1.1> User-Agent: curl/7.16.3> Host: www.example.com> Accept: */*>
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 14/22Talking HTTP: the response
$ curl -v http://www.example.com* About to connect() to www.example.com port 80 (#0)* Trying 208.77.188.166... connected* Connected to www.example.com (208.77.188.166) port 80 (#0)> GET / HTTP/1.1> User-Agent: curl/7.16.3> Host: www.example.com> Accept: */*>< HTTP/1.1 200 OK< Date: Sun, 16 Aug 2009 16:05:42 GMT< Server: Apache/2.2.3 (Red Hat)< Last-Modified: Tue, 15 Nov 2005 13:24:10 GMT< ETag: "b80f4-1b6-80bfd280"< Accept-Ranges: bytes< Content-Length: 438< Connection: close
< Content-Type: text/html; charset=UTF-8
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 15/22Talking HTTP: the document
$ curl -v http://www.example.com* About to connect() to www.example.com port 80 (#0)* Trying 208.77.188.166... connected* Connected to www.example.com (208.77.188.166) port 80 (#0)> GET / HTTP/1.1> User-Agent: curl/7.16.3> Host: www.example.com> Accept: */*>< HTTP/1.1 200 OK< Date: Sun, 16 Aug 2009 16:05:42 GMT< Server: Apache/2.2.3 (Red Hat)< Last-Modified: Tue, 15 Nov 2005 13:24:10 GMT< ETag: "b80f4-1b6-80bfd280"< Accept-Ranges: bytes< Content-Length: 438< Connection: close
< Content-Type: text/html; charset=UTF-8<<HTML>..........
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 16/22The most important bits
> GET / HTTP/1.1> Host: www.example.com>< HTTP/1.1 200 OK
< Content-Type: text/html; charset=UTF-8<<HTML>..........
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 17/22Practical 2: retrieving data
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 18/22Practical 2: retrieving data
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 19/22Web APIs
! It’s just HTTP! At least, the good ones are
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 20/22Web API challenges
! HTTPS! Crypto (e.g. OAuth)! XML parsing!
JSON parsing! Large documents
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 21/22Practical 3: serving data
8/13/2019 ArduinoEthernetW5100.pdf
http://slidepdf.com/reader/full/arduinoethernetw5100pdf 22/22P ti l 3 i g d t