Line | |
---|
1 | /*
|
---|
2 | Y炭n HTTP Client
|
---|
3 |
|
---|
4 | This example for the Arduino Y炭n shows how create a basic
|
---|
5 | HTTP client that connects to the internet and downloads
|
---|
6 | content. In this case, you'll connect to the Arduino
|
---|
7 | website and download a version of the logo as ASCII text.
|
---|
8 |
|
---|
9 | created by Tom igoe
|
---|
10 | May 2013
|
---|
11 |
|
---|
12 | This example code is in the public domain.
|
---|
13 |
|
---|
14 | http://arduino.cc/en/Tutorial/HttpClient
|
---|
15 |
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include <Bridge.h>
|
---|
19 | #include <HttpClient.h>
|
---|
20 |
|
---|
21 | void setup() {
|
---|
22 | // Bridge takes about two seconds to start up
|
---|
23 | // it can be helpful to use the on-board LED
|
---|
24 | // as an indicator for when it has initialized
|
---|
25 | pinMode(13, OUTPUT);
|
---|
26 | digitalWrite(13, LOW);
|
---|
27 | Bridge.begin();
|
---|
28 | digitalWrite(13, HIGH);
|
---|
29 |
|
---|
30 | Serial.begin(9600);
|
---|
31 |
|
---|
32 | while (!Serial); // wait for a serial connection
|
---|
33 | }
|
---|
34 |
|
---|
35 | void loop() {
|
---|
36 | // Initialize the client library
|
---|
37 | HttpClient client;
|
---|
38 |
|
---|
39 | // Make a HTTP request:
|
---|
40 | client.get("http://arduino.cc/asciilogo.txt");
|
---|
41 |
|
---|
42 | // if there are incoming bytes available
|
---|
43 | // from the server, read them and print them:
|
---|
44 | while (client.available()) {
|
---|
45 | char c = client.read();
|
---|
46 | Serial.print(c);
|
---|
47 | }
|
---|
48 | Serial.flush();
|
---|
49 |
|
---|
50 | delay(5000);
|
---|
51 | }
|
---|
52 |
|
---|
53 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.