Ethernet Shield
-
Upload
tinker-london -
Category
Self Improvement
-
view
710 -
download
0
description
Transcript of Ethernet Shield
![Page 1: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/1.jpg)
Arduino Ethernet Shield
![Page 2: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/2.jpg)
Arduino + Ethernet
![Page 3: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/3.jpg)
Twittering plant
![Page 4: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/4.jpg)
Capabilities
★Wiznet W5100 ethernet chip★Client★Server★TCP★UDP★Four channels
![Page 5: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/5.jpg)
The Ethernet library
★All looks like a serial port
★Ethernet: initialise network★Client: connect to a port on a server, then read() and write()★Server: waits for a connection on a port
![Page 6: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/6.jpg)
Ethernet limitations
★DHCP needs 3rd-party library★No DNS★DIY for high-level protocols (no HTTP library, etc) - lots of print() statements★Library memory footprint
![Page 7: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/7.jpg)
Practical 1: on the network
![Page 8: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/8.jpg)
Practical 1: on the network
Example file:ChatServer
![Page 9: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/9.jpg)
Configuration
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);
![Page 10: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/10.jpg)
Talking HTTP
![Page 11: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/11.jpg)
Talking HTTP
$ curl -v http://www.example.com
![Page 12: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/12.jpg)
Talking 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)
![Page 13: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/13.jpg)
Talking 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: */*>
![Page 14: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/14.jpg)
Talking 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
![Page 15: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/15.jpg)
Talking 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>..........
![Page 16: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/16.jpg)
The most important bits
> GET / HTTP/1.1> Host: www.example.com> < HTTP/1.1 200 OK< Content-Type: text/html; charset=UTF-8< <HTML>..........
![Page 17: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/17.jpg)
Practical 2: retrieving data
![Page 18: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/18.jpg)
Practical 2: retrieving data
Example file:WebClient
![Page 19: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/19.jpg)
Web APIs
★It’s just HTTP★At least, the good ones are
![Page 20: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/20.jpg)
Web API challenges
★HTTPS★Crypto (e.g. OAuth)★XML parsing★JSON parsing★Large documents
![Page 21: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/21.jpg)
Practical 3: serving data
![Page 22: Ethernet Shield](https://reader034.fdocuments.in/reader034/viewer/2022052410/5552db94b4c90532498b4b4e/html5/thumbnails/22.jpg)
Practical 3: serving data
Example file:WebServer