|
6 | 6 | // outputs the content to the serial port
|
7 | 7 |
|
8 | 8 | #include <SPI.h>
|
9 |
| -#include <HttpClient.h> |
10 |
| -#include <Ethernet.h> |
11 |
| -#include <EthernetClient.h> |
| 9 | +#include <ArduinoHttpClient.h> |
| 10 | +#include <WiFi101.h> |
12 | 11 |
|
13 | 12 | // This example downloads the URL "http://arduino.cc/"
|
14 | 13 |
|
| 14 | +char ssid[] = "yourNetwork"; // your network SSID (name) |
| 15 | +char pass[] = "secretPassword"; // your network password |
| 16 | + |
15 | 17 | // Name of the server we want to connect to
|
16 | 18 | const char kHostname[] = "arduino.cc";
|
17 | 19 | // Path to download (this is the bit after the hostname in the URL
|
18 | 20 | // that you want to download
|
19 | 21 | const char kPath[] = "/";
|
20 | 22 |
|
21 |
| -byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; |
22 |
| - |
23 | 23 | // Number of milliseconds to wait without receiving any data before we give up
|
24 | 24 | const int kNetworkTimeout = 30*1000;
|
25 | 25 | // Number of milliseconds to wait if no data is available before trying again
|
26 | 26 | const int kNetworkDelay = 1000;
|
27 | 27 |
|
28 | 28 | void setup()
|
29 | 29 | {
|
30 |
| - // initialize serial communications at 9600 bps: |
31 |
| - Serial.begin(9600); |
| 30 | + //Initialize serial and wait for port to open: |
| 31 | + Serial.begin(9600); |
| 32 | + while (!Serial) { |
| 33 | + ; // wait for serial port to connect. Needed for native USB port only |
| 34 | + } |
32 | 35 |
|
33 |
| - while (Ethernet.begin(mac) != 1) |
34 |
| - { |
35 |
| - Serial.println("Error getting IP address via DHCP, trying again..."); |
36 |
| - delay(15000); |
37 |
| - } |
| 36 | + // attempt to connect to Wifi network: |
| 37 | + Serial.print("Attempting to connect to WPA SSID: "); |
| 38 | + Serial.println(ssid); |
| 39 | + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { |
| 40 | + // unsuccessful, retry in 4 seconds |
| 41 | + Serial.print("failed ... "); |
| 42 | + delay(4000); |
| 43 | + Serial.print("retrying ... "); |
| 44 | + } |
| 45 | + |
| 46 | + Serial.println("connected"); |
38 | 47 | }
|
39 | 48 |
|
40 | 49 | void loop()
|
41 | 50 | {
|
42 | 51 | int err =0;
|
43 | 52 |
|
44 |
| - EthernetClient c; |
| 53 | + WiFiClient c; |
45 | 54 | HttpClient http(c);
|
46 | 55 |
|
47 | 56 | err = http.get(kHostname, kPath);
|
|
0 commit comments